當打開其它網頁(如百度)時不能正確接收prompt的函數返回值
webUrl = prompt("請輸入打開的網址(默認為慕課網)","http://www.xianlaiwan.cn/");
? ? ? ? ? ? document.write(webUrl);
? ? ? ? ? ? if (webUrl) {
? ? ? ? ? ? ? ? window.open(webUrl,'_blank','width=400,height=500,menubar=no,toolbar=no');?
? ? ? ? ? ? }?
更改消息為www.baidu.com時,document.write(webUrl)輸出的是www.baidu.com,但是新窗口卻打不開網頁,并且是http://www.xianlaiwan.cn/code/www.baidu.com,請問這是為什么?
2017-03-26
剛學完這個,其實沒太看懂你的意思,但是我把你的代碼改了一下,你可以看看是不是你想要的結果。
<script type="text/javascript">
? var webUrl = prompt("請輸入打開的網址(默認為慕課網)","http://www.xianlaiwan.cn/");
??????????? document.write("webUrl");
??????????? var baidu="http://www.baidu.com";
??????????? if (webUrl=="百度") {
??????????????? window.open(baidu,'_blank','width=400,height=500,menubar=no,toolbar=no');
??????????? }
??????????? else{
??????????????? alert("lalalala")
??????????? }
? </script>
2017-04-07
所以變量不是不能正確的接收prompt()的值,而是window.open()函數里的第一個參數必須需要帶協議!
2017-04-04
第一個參數url,必須帶http,不然就會有問題,我猜想可能和url的結構有關,url在定義的時候就是:模式/協議 + 地址