windows.location.href不适用于Firefox3 [英] windows.location.href not working on Firefox3
问题描述
我们有一个名为move的JavaScript函数,它只是windows.location.href = 任何给定的锚点。
此功能适用于IE,Opera和Safari,但不知何故在Firefox中被忽略。对Google进行研究并不能产生令人满意的答案。为什么不起作用。
是否有任何JavaScript专家知道这种行为,以及通过JavaScript跳转到锚点的最佳做法是什么?
在某些浏览器中, window.location.href
是一个只读属性,不是设置位置的最佳方式(即使技术上它应该允许你)。如果您自己使用 location
属性,那么您应该在所有浏览器中重定向。
$ b Mozilla的文档包含关于如何使用
window.location
对象的一个非常详细的解释。 https://developer.mozilla.org/zh/DOM/window.location
We have a JavaScript function named "move" which does just "windows.location.href = any given anchor".
This function works on IE, Opera and Safari, but somehow is ignored in Firefox. Researching on Google doesn't produce a satisfactory answer why it doesn't work.
Does any JavaScript guru knows about this behavior, and what would be the best practice to jump to an anchor via JavaScript?
Have you tried just using
window.location = 'url';
In some browsers, window.location.href
is a read-only property and is not the best way to set the location (even though technically it should allow you to). If you use the location
property on its own, that should redirect for you in all browsers.
Mozilla's documentation has a pretty detailed explanation of how to use the window.location
object.
https://developer.mozilla.org/en/DOM/window.location
这篇关于windows.location.href不适用于Firefox3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!