2015-12-15 34 views
-1

JS编码错误!关于外部链接不运行额外的代码

if (confirm("By clicking Ok, you agree to letting us log your IP! If you say Cancel, you will be sent back to Google's homepage!") != true) { 
 
    window.location.replace("http://google.com"); 
 
    console.log("Website.js, loaded! No ERROR!"); 
 
}
h1 { 
 
    text-align: center; 
 
    padding-top: 50px 
 
} 
 
p { 
 
    text-align: center; 
 
    font-size: 18px; 
 
} 
 
#pd { 
 
    padding-top: 20px; 
 
    width: 300px; 
 
    margin: auto; 
 
} 
 
ul { 
 
    font-size: 18px; 
 
    text-align: center; 
 
    padding-top: 20px 
 
} 
 
#form { 
 
    width: 150px; 
 
    margin: auto; 
 
    text-align: center; 
 
    font-size: 18px; 
 
    padding-top: 20px; 
 
} 
 
#clientIP { 
 
    font-weight: bold; 
 
    font-size: 16; 
 
    text-align: center; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title></title> 
 
</head> 
 

 
<body> 
 
    <h1></h1> 
 
    <p id="clientIP"></p> 
 
    <div id="pd"> 
 
    <p></p> 
 
    <h1></h1> 
 
    <ul> 
 
     <li></li> 
 
     <br> 
 
     <li></li> 
 
     <br> 
 
     <li></li> 
 
     <br> 
 
     <li></li> 
 
     <br> 
 
     <li></li> 
 
     <br> 
 
    </ul> 
 
    </div> 
 
    <link rel='stylesheet' type='text/css' href='Website.css' /> 
 
    <script src="Website.js"></script> 
 
    <script type="text/javascript" src="https://www.l2.io/ip.js?var=myip"></script> 
 
    <script type="text/javascript"> 
 
    document.getElementById("clientIP").innerHTML = "Your IP is - " + myip; 
 
    console.log("File that retrives IP has been run! No ERROR!") 
 
    </script> 
 
</body> 
 

 
</html>

所以我很偏执,因此丢失的文本,但错误的是,当一切都运行和工作,Website.js'日志中没有出现!它烦扰我! Website.js是JS代码.....是的,但我很烦恼,当我检查元素时,日志不会出现!

回答

2

您正在更改窗口的位置,因此在调用log方法之前将您的所有代码替换为http://google.com的代码。你的脚本永远不会运行这个命令,因为你的脚本在上一个命令期间被替换了,因此永远不会到达后续命令。

+0

我觉得真的很愚蠢,但谢谢!大声笑这行应该是在一个else语句! –

+0

@SeandaPotato哈哈不用担心。我也觉得哑巴。如果我刚刚在代码中滚动,我会注意到这一点,并能够给出更具体的建议。 –

相关问题