windows.location.href 不适用于 Firefox3 [英] windows.location.href not working on Firefox3

查看:18
本文介绍了windows.location.href 不适用于 Firefox3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个名为move"的 JavaScript 函数,它只执行windows.location.href = 任何给定的锚点".
此功能适用于 IE、Opera 和 Safari,但不知何故在 Firefox 中被忽略.在 Google 上进行研究并没有得出令人满意的答案为什么它不起作用.
有没有 JavaScript 专家知道这种行为,通过 JavaScript 跳转到锚点的最佳做法是什么?

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?

推荐答案

你有没有试过只用

window.location = 'url';

在某些浏览器中,window.location.href 是只读属性,并不是设置位置的最佳方式(尽管从技术上讲它应该允许您这样做).如果您单独使用 location 属性,它应该会在所有浏览器中为您重定向.

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 的文档非常详细地解释了如何使用 window.location 对象.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆