This does not work in Safari and Chrome:
$(".myButton").click(function(){
window.location.href('www.blahblahblah.com');
});
what's the solution?
window.location.href is not a function and therefor you cannot call it, you can however assign a value to it: (Also you should be using http:// when redirecting to another domain)
$(".myButton").click(function(){
window.location.href = 'http://www.blahblahblah.com';
});
EDIT: Corrected my first statement and added the part about http://
Had a similar problem. In chrome, return false; solved the problem.
if(confirm('Are you sure you wish to delete this order?'))
{
location.href='delete_order.asp?id=20'; **return false;**}
else
{return false;}
The above code works in Chrome and IE9
window.location.assign('http://www.google.com')
is the function you're looking for.
It's the equivalent of
window.location = 'http://www.google.com';
Related
I have a problem with window.location.href.
I'm trying to redirect to a page with the following code:
window.location.href = "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;
It works perfectly on Firefox and Chrome, however in IE10 the browser freezes and I have to restart it. Sometimes it redirect to the desired page, but the parameters do not pass through. I have been looking for a solution, for example this one:
Window.Location Not Working In IE?
But the proposed solution do not work for me.
Do somebody know how to deal with this?
The problem is likely due to the value of your variables. If they contain special or invalid characters, those needs to be passed through encodeURIComponent before being assigned to window.location.href.
For some reason IE only like full url.
I have te same problem and fix it adding the full url like this:
var baseURL = 'http://www.your_url.com/';
window.location.href = baseURL + "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;
Use encodeURIComponent() to escape your url:
window.location.href = encodeURIComponent("juego.html?modoJuego=" + modoJuego + "&etapa=" + etapa + "&rango=" + rango);
Works fine on Firefox 23.0, Chrome 28.0.1500.95 and Internet Explorer 10.
Try window.location.replace(...) instead.
Refer this question for information:
How to redirect to another webpage in JavaScript/jQuery?
I have been trying to figure this out all afternoon, but have given up and now turning to you clever people to help :)
I have the following Jquery/Javascript function, which is working fine in Chrome - BUT in IE nothing happens?
$(".btnsubmitpost").click(function () {
var topicid = $(this).attr('rel');
var sbody = tinyMCE.get('txtPost').getContent();
$('.topicpostlistnewpost').remove();
$('.postsuccess').show();
$.post("/myurl/" + topicid + ".aspx",
{ "postcontent": sbody },
function (data) {
var returnUrl = $("value", data).text();
window.location.href = returnUrl;
return false;
});
return false;
});
I have tried window.location, window.location.href both with full urls and absolute Urls but IE just doesn't like it? Any ideas?
The function just gets a Url back from a post, and is supposed to redirect the user to the Url. But like I say, works in Chrome fine just not in IE (Tried IE8 and IE9)
Just for anyone having the same issue, the problem was because the window.location was inside the Ajax post method.
Just replace the window.location with a function() that then calls the window.location or do it after the Ajax call completely.
I'm just building a simple ajax site but running into a problem in safari and chrome. I'm just creating a simple redirect if the user goes to a page i.e.
"/blog"
they would be redirected to
"/#/blog"
code :
url = window.location.pathname
if(url != "/") {
window.location.pathname = "/#" + url
}
This is working great in FireFox but unfortunatly webkit browsers are turning the "#" into a "%23" and giving a 404, for example:
"/%23/blog"
How can I prevent this?
Thanks,
Alex
pathname refers to everything after the host, and before the query string and hash. Consider this instead:
window.location.hash = window.location.pathname;
window.location.pathname = "/";
I'm not exactly sure which browser(s) are implementing the JavaScript spec correctly, but WebKit's behavior seems correct to me.
You are setting pathname, which, by definition, does not include the hash. Webkit is trying to fix that for you (Firefox just made a better guess of what you wanted). Try this:
window.location = '/#/blog';
I have a small problem. For some weird reason any attempt to change url via javascript, be it window.open, window.location, window.location.href, etc. doesnt move to the desired page, but adds it to end of the url. It doesnt even matter what IE version, from 6-8
E.g.
http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639
ends in
http://localhost/blabla/produkt/philips-fc-861501-animal-care/added-by-javascript
I have no idea why this happens...
On this page
http://localhost/blabla/objednat-tovar?step=deal-detail
it works as intended.
Any help is appreciated...
EDIT:
Some code.
I am on
http://localhost/blabla/produkt/philips-fc-861501-animal-care/3639
// code
test
function aaa(where) {
window.location = where;
}
Ends in
http://localhost/blabla/produkt/philips-fc-861501-animal-care/new_location
Same thing happens with window.location.href, window.open and only in IEs
I'm guessing that the browser tries to parse the location as a URL and if it fails then, presumably, it does whatever it wants (IE seems to append the string to the current location). For example:
window.location = 'about:blank'; // OK, since it's a valid pseudo-url.
window.location = 'foo'; // No effect, since this isn't a URL.
window.location = 'http://example.com/'; // OK, browse to that page.
window.location = 'bar'; // Depends on what the browser wants to do...
you don't need javascript: here
test
function aaa(where) {
window.location = where;
}
I would like to have the History.back(); functionality with a complete refresh of previous page.
Any idea how to do that (and make it work in IE, FF and Chrome).
You could redirect (by window.location) to document.referrer
i.e.
window.location.href = document.referrer;
Internet Explorer fix for passing referrer to a particular location:
if(IE){ //IE, bool var, has to be defined
var newlocation = document.createElement('a');
newlocation.href = URLtoCall;
document.body.appendChild(newlocation);
newlocation.click();
}
You can also use the location replace() method:
window.location.replace(document.referrer)