簡體   English   中英

沒有window.location和window.open之間的區別

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

我發現當設置location屬性時,頁面不會重定向util運行javascript,但window.open現在會運行。 為什么? 有關於此的一些文件嗎? 以下是測試代碼..

<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在修改location.href打開一個新的窗口/選項卡,重定向當前頁面。

在腳本運行之前,重定向不會發生的原因只是瀏覽器在腳本運行時幾乎不會做任何事情 - 它不是一個多線程環境。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM