-
Feb 28th, 2017, 08:24 AM
#1
Thread Starter
New Member
javascript window.location.href doesn´t fire
Hi,
Recently, I´ve had to update some code due to some "upgrade" I guess.
I changed window.navigate to window.location.href where it was needed, and it worked for most cases.
However, there is one that doesn´t work. I´ve placed an alert after it and it displays correctly, so it´s not that the code aborts.
I hope this is a known issue. The function is being called from another function. The code is placed directly in the .aspx for the moment.
Thanks!
Fabean
Code:
window.location.href = "www.google.com"
alert("klart");
-
Feb 28th, 2017, 10:27 AM
#2
Re: javascript window.location.href doesn´t fire
What browsers are you testing with?
Try adding http:// in your href value.
Code:
window.location.href = 'http://www.google.com';
Last edited by KGComputers; Feb 28th, 2017 at 10:31 AM.
-
Feb 28th, 2017, 10:43 AM
#3
Thread Starter
New Member
Re: javascript window.location.href doesn´t fire
Thanks for answering,
I´ve tried with chrome and firefox.
I´ve also tried a number of different url:s, but the line simply doesn´t execute. The following alert executes though.
Fabean
-
Feb 28th, 2017, 10:44 AM
#4
Re: javascript window.location.href doesn´t fire
You need to include the http:// otherwise it will try to use it as a relative part rather than an absolute.
-tg
-
Feb 28th, 2017, 10:47 AM
#5
Re: javascript window.location.href doesn´t fire
Have you tried the suggested fix in post #2 (adding http:// to the url)?
-
Feb 28th, 2017, 10:55 AM
#6
Thread Starter
New Member
Re: javascript window.location.href doesn´t fire
Originally Posted by KGComputers
Have you tried the suggested fix in post #2 (adding http:// to the url)?
Yes, I did. Both with and without. All kinds of adresses.
However I should say that I am testing locally it locally.
Fabean
-
Feb 28th, 2017, 11:03 AM
#7
Re: javascript window.location.href doesn´t fire
I´ve placed an alert after it and it displays correctly, so it´s not that the code aborts.
Remove the alert(s) statement(s) following window.location.href statement. I tested the suggested fix in Firefox, Chrome and IE10.
- kgc
-
Feb 28th, 2017, 11:05 AM
#8
Re: javascript window.location.href doesn´t fire
Oh, also it only works (I believe) if you access it via a server address... even if iti's http://localhost/test.html if you're double-clicking an html, then the rules change...
I know there's some quirky rules regarding changing the href from js code like this... which is why I try to avoid doing so, and opt for doing a meta refresh with the new url.
Weird that it seems to work sometimes for you, but not in one case.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|