admin管理员组文章数量:1414621
For some reason, using window.location.href
doesn't change the URL in the user's address bar. Is there any reason why I'm getting this behavior?
CODE
Earlier, I posted to code here. But I see that I'm in a frame. For anyone who happens to have the same issue, window.top.location.href = 'page.htm'; will do the trick.
PS. Apologies for not mentioning the frame aspect. It was an tiny, subtle use of frames. Had I known, I wouldn't have asked the question :)
Thanks to all!
For some reason, using window.location.href
doesn't change the URL in the user's address bar. Is there any reason why I'm getting this behavior?
CODE
Earlier, I posted to code here. But I see that I'm in a frame. For anyone who happens to have the same issue, window.top.location.href = 'page.htm'; will do the trick.
PS. Apologies for not mentioning the frame aspect. It was an tiny, subtle use of frames. Had I known, I wouldn't have asked the question :)
Thanks to all!
Share Improve this question edited Sep 24, 2010 at 2:53 Kyle Cureau asked Sep 24, 2010 at 1:34 Kyle CureauKyle Cureau 19.4k23 gold badges77 silver badges104 bronze badges 6-
3
Can you provide a code sample? Because
window.location.href
normally does what I think you want to do… So either I don't understand what you want or something else is wrong. – David Wolever Commented Sep 24, 2010 at 1:56 -
in a callback, I've added
window.location.href = "home.html";
So the page call and redirect are made, but the url remains the same (IE and FF tested) – Kyle Cureau Commented Sep 24, 2010 at 2:05 - @Emile: Have you confirmed that the callback is being called? You should provide code. – Cristian Sanchez Commented Sep 24, 2010 at 2:08
- @Daniel, Yes. I've also just tested changing the code to an external URL window.location.href = "google." and no luck. But now I believe you guys that the address bar should change. I tested it in clean code space and it does what you all say it should. Any other ideas? – Kyle Cureau Commented Sep 24, 2010 at 2:10
- @Emile: Could you post the code, including where you assign the callback and when it's triggered? – Cristian Sanchez Commented Sep 24, 2010 at 2:11
3 Answers
Reset to default 4window.top.location.href = 'home.html' changed the address bar for me, because unknowingly I was caught in a frame.
Thanks Stack Overflow for at least confirming that the behavior I was getting was unusual.
You can do it with a frameset and the adress bar won't change, no matter where users navigate to.
But as already mentioned, even Internet Explorer -since IE7- focuses on the User to prevent stuff like that, the User has the right to know where he is surfing to - it is a security issue.
Imagine you e to some website that looks clean and friendly and the Site redirects you to an array of phishing sites without you or your browser security noticing it. The Site owner could get all your private info, for e.g. your clipboard content or geolocation data and while you are at ease, the Site owner empties your bank account. Just an example.
In addition to your below answer I tried window.location.href on Firefox 3.6 and it works as expected.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>urlRefresh</title>
</head>
<body>
<input type="button" value="changeAdress" id="changeAdress" />
<script>
document.getElementById('getValues').onclick = function() {
window.location.href = "http://www.bing.";
}
</script>
</body>
</html>
If you click the button changeAdress JavaScript issues a GET Request via your browser to the desired Website.
See http://plixi./p/46770650
You can't programatically change the address bar (think of the phishing possibilities).
Best you can do is change the url with window.location
, i.e. navigate the user there.
The process of the address bar changing this way is abstracted away :)
本文标签: javascriptwindowlocationhref but where the address bar changesStack Overflow
版权声明:本文标题:javascript - window.location.href but where the address bar changes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745185964a2646687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论