Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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.host比较URL?_Javascript_Url_Comparison_Window.location - Fatal编程技术网

Javascript 通过window.location.host比较URL?

Javascript 通过window.location.host比较URL?,javascript,url,comparison,window.location,Javascript,Url,Comparison,Window.location,我想比较一下当前网页的URL。我的第一个想法是使用window.location.host: if (window.location.host == example.com) { //code to be executed if condition is true } 但这不起作用。还有其他想法吗 哦,我不太懂javascript。提前谢谢。你可以照你说的做。只需记住将字符串文字放在引号中 if (window.location.host == "example.com") {

我想比较一下当前网页的URL。我的第一个想法是使用window.location.host:

if (window.location.host == example.com) {
    //code to be executed if condition is true
}
但这不起作用。还有其他想法吗


哦,我不太懂javascript。提前谢谢。

你可以照你说的做。只需记住将字符串文字放在引号中

if (window.location.host == "example.com") {
    //code to be executed if condition is true
}

你可以照你说的做。只需记住将字符串文字放在引号中

if (window.location.host == "example.com") {
    //code to be executed if condition is true
}

@PatrickLenz别忘了,你可以通过单击旁边的复选标记,将帮助你的人的答案标记为问题的解决方案来奖励他们。对不起。我是stackoverflow的新手;)@PatrickLenz别忘了,你可以通过单击旁边的复选标记,将帮助你的人的答案标记为问题的解决方案来奖励他们。对不起。我是stackoverflow的新手;)