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

查看:104
本文介绍了windows.location.href不适用于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屋!

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