0

I used jquery-1.8.0.min.js on my site and I need make redirect in some situations.

I was try this:

$('<div></div>').appendTo('body') .html('<div><h4>Some text....</h4></div>') .dialog({ modal: true, title: 'Dialog title...', zIndex: 10000, autoOpen: true, width: 'auto', resizable: false, draggable: false, buttons: { Ok: function () { $(this).dialog("close"); var loc = window.location; var currentURL = loc.protocol + '//' + loc.host + loc.pathname; var newUrl = loc.protocol + '//' + loc.host + 'Account/LogOn?ReturnUrl=' + urlencode(currentURL); $('<div style="dispaly:none;"></div>').appendTo('<body>').html('<a id="loginredirect" href="' + newUrl + ' "><br /></a>'); $('#loginredirect').click(); } }, close: function (event, ui) { $(this).remove(); } }); 

but this doesnt work :-( so i try this:

$('<div></div>').appendTo('body') .html('<div><h4>Some text....</h4></div>') .dialog({ modal: true, title: 'Dialog title...', zIndex: 10000, autoOpen: true, width: 'auto', resizable: false, draggable: false, buttons: { Ok: function () { $(this).dialog("close"); var loc = window.location; var currentURL = loc.protocol + '//' + loc.host + loc.pathname; var newUrl = loc.protocol + '//' + loc.host + 'Account/LogOn?ReturnUrl=' + urlencode(currentURL); $(window.location).attr('href', newUrl); } }, close: function (event, ui) { $(this).remove(); } }); 

but this doesnt work too...

Any idea where is the problem?

Thanks

EDIT 1: If i was trying window.location.hrej = newUrl, FF ErrorConsole show me this: NS_ERROR_MALFORMED_URI: Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIDOMLocation.href] in localhost/Content/scripts/jquery-1.8.0.min.js

and browser dont redirect to newUrl in IE, FF and Chrome...

5
  • location object is not a DOM element and you cannot convert it to a jQuery object. Commented Sep 13, 2012 at 13:43
  • window.location.href = newUrl should do the trick Commented Sep 13, 2012 at 13:43
  • 1
    can you alert newUrl? my guess is, you need a / after the loc.host Commented Sep 13, 2012 at 13:48
  • karthikr: really thanks... I am stupid :-) ... a / was really missing... Commented Sep 13, 2012 at 13:54
  • I will just make this an answer for future reference. Commented Sep 13, 2012 at 13:56

3 Answers 3

5

You don't need a jquery for this , just try,

window.location.href = new_url; 
Sign up to request clarification or add additional context in comments.

Comments

1

newURL is missing a trailing / after loc.host

var newUrl = loc.protocol + '//' + loc.host + 'Account/LogOn?ReturnUrl=' + urlencode(currentURL); window.location.href = newUrl; 

Comments

1

In your second example, replace this line:

$(window.location).attr('href', newUrl); 

for this one

window.location.href = newUrl; 

that should do what you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.