简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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