Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么window.location.href会再次追加url_Javascript_Jquery_Html - Fatal编程技术网

Javascript 为什么window.location.href会再次追加url

Javascript 为什么window.location.href会再次追加url,javascript,jquery,html,Javascript,Jquery,Html,在我的代码中,我分配以下内容: window.location.href = "www.example.com/test"; 但当页面实际加载时,浏览器URL为www.example.com/test/www.example.com/test。我没有向URL追加任何内容,我也不确定它是如何再次追加URL的 因为你忘了协议。如果忽略协议,window.location.href认为您正试图访问一个名为www.example.com的文件夹,相对于您当前所在的页面 window.location.

在我的代码中,我分配以下内容:

window.location.href = "www.example.com/test";

但当页面实际加载时,浏览器URL为
www.example.com/test/www.example.com/test
。我没有向URL追加任何内容,我也不确定它是如何再次追加URL的

因为你忘了协议。如果忽略协议,
window.location.href
认为您正试图访问一个名为
www.example.com
文件夹,相对于您当前所在的页面

window.location.href=”http://www.example.com/test/“
将确保您访问外部网站
www.example.com


希望这有帮助!:)

我认为您缺少了“http”或“https”部分。你试过以下方法吗

window.location.href = "https://www.example.com/test";

window.location.href = "http://www.example.com/test";