点击之间有什么区别:
<a href />
Run Code Online (Sandbox Code Playgroud)
与
调用 window.location.href = ...
?
nic*_*ckf 41
只要有可能,你应该使用<a href="foo.html">过window.location.href,对于一些很好的理由.
window.location打破所有这些设置window.location.href = 'thepage.html'与调用相同:
window.open('thepage.html', '_self');
Run Code Online (Sandbox Code Playgroud)
即目标仅限于同一窗口,因为它是location属性的位置.这与单击没有目标属性的链接具有相同的效果:
<a href="thepage.html">...</a>
Run Code Online (Sandbox Code Playgroud)
您可以使用open方法来指定不同的目标,例如新窗口:
window.open('thepage.html', '_blank');
Run Code Online (Sandbox Code Playgroud)
这与单击具有该目标的链接具有相同的效果:
<a href="thepage.html" target="_blank">...</a>
Run Code Online (Sandbox Code Playgroud)
您还可以使用open方法打开一个新窗口.返回值是对窗口的引用,因此您可以使用它来设置该窗口的位置而不是当前窗口:
var w = window.open('about:blank', '_blank');
w.location.href = 'thepage.html';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16909 次 |
| 最近记录: |