Javascript window.location是否为非阻塞操作?

Javascript window.location是否为非阻塞操作?,javascript,Javascript,在处理缺陷时,我遇到了与我的理解不同的window.location行为。在出现此问题之前,我认为将值分配给window.location会阻止其他操作并继续重定向 // Try to answer the questions before you run this script on JSFiddle. // 1. Which site is going to load as a result of redirect method - apple.com or mashable.com? //

在处理缺陷时,我遇到了与我的理解不同的window.location行为。在出现此问题之前,我认为将值分配给window.location会阻止其他操作并继续重定向

// Try to answer the questions before you run this script on JSFiddle.
// 1. Which site is going to load as a result of redirect method - apple.com or mashable.com?
// 2. Will the console log 'script added' print in console?
function redirect(url) {
  var el = document.createElement('script');
  var head = document.getElementsByTagName("head")[0];
  var content = "window.location.href='"+url+"'";

  el.innerHTML = content;

  head.appendChild(el);
}

console.log('adding scripts');
redirect('http://apple.com');
redirect('http://mashable.com');
console.log('script added');

我试图寻找解释这种行为的文档,但找不到任何文档。详细解释window.location的任何文档或文章都会很有用。

在Javascript中,设置
window.location.href
通常是一种非阻塞操作。

在DNS解析新页面时,仍然可以运行Javascript操作。因此,如果在完成此操作之前更改
location.href
,则将重新开始此过程

您可以阅读
window.location
(特别是
window.location.assign
)如何在的Javascript中执行


设置了
window.location
对象后,web浏览器将启动子例程。

您的意思是?我不羡慕你。HTML5不需要阻止
窗口。location
属性分配操作。那么2个重定向应该做什么呢?如果你点击了一个链接,你还能在浏览器加载页面之前点击另一个链接吗。。。这是你的答案谢谢@NextLocal。我不是在寻找解决办法。我的目的是了解window.location.href是一个非阻塞操作的文档记录在哪里。答案中的引号来自哪里?您能否详细说明您的代码示例的具体功能?如果是“阻塞”-那么第二个重定向调用的目的是什么?@Moorthy:为什么在任何地方都要这样声明?这是一个变量赋值。@zerkms第二个重定向调用的目的只是显示它没有运行:)