这是html和javascript中使用的最佳重定向方法

Which is the best redirection method used in html and javascript?

本文关键字:最佳 重定向 方法 html javascript 这是      更新时间:2023-09-26

我已经看到了location.hrefwindow.openwindow.location等重定向。

  1. 我想知道哪种是最好的方法,并且适用于每台设备。
  2. 如果我使用 setTimer 并在加载页面元素后加载脚本,还有一件事是最好的方法?

请分别回答1和2问题,并提前表示感谢。

window.location.href = 'URL';

是更改当前窗口位置的标准实现。

document.location 是一个(已弃用但仍存在)只读字符串属性,由 document.url 替换。

window.location也会影响框架,

我发现的最好的形式是:

parent.window.location.href

更糟糕的是:

parent.document.URL

我做了一个大规模的浏览器测试,一些带有几个插件的罕见IE在第二种形式中未定义。