简体   繁体   English

没有window.location和window.open之间的区别

[英]aboout the difference between window.location and window.open

i find that when the location attribute is set ,the page will not redirect util the javascript run over, but the window.open will run right now. 我发现当设置location属性时,页面不会重定向util运行javascript,但window.open现在会运行。 why? 为什么? is there some documents about this?? 有关于此的一些文件吗? below is test codes.. 以下是测试代码..

<html>
<head>
<script type="text/javascript">
window.location.href = ("http://www.baidu.com");
window.open('http://google.com');
//alert(1);
</script>
</head>
<body>
<img src="http://pic5.bbzhi.com/fengjingbizhi/zhongguolvyoufengguanggaoqingbizhi/zhongguolvyoufengguanggaoqingbizhi_448610_9.jpg?q=1"
/>
</body>
</html>

window.open opens a new window/tab while modifying location.href redirects the current page. window.open在修改location.href打开一个新的窗口/选项卡,重定向当前页面。

The reason why the redirect does not happen until your script finished is simply that the browser pretty much won't do anything while a script is running - it's not a multithreaded environment. 在脚本运行之前,重定向不会发生的原因只是浏览器在脚本运行时几乎不会做任何事情 - 它不是一个多线程环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM