URL重定向Javascript? 我試圖用http://重定向輸入的網址,然後提示,直到找到http://,如果找到它,它會將它引導到輸入的網站。URL重定向Javascript
繼承人到目前爲止我的代碼:
function enter() {
var keepGoing = true;
var email;
while (keepGoing) {
keepGoing = false
email = prompt("Please Enter Website Address");
// Website Address validation to see if it has http://
if (email.indexOf('http://') === -1) {
alert("Not valid Web Address");
keepGoing = true;
}
// if nothing was entered
else if (email == '') {
var email = prompt("Please Enter Valid Web Address");
}
}
}
備註:'keepGoing'變量是不必要的。 – JJJ 2013-03-09 07:28:08
'email.indexOf('http://')=== -1'應該是'email.indexOf('http://')!= 0',因爲你必須驗證http://是第一部分的網站地址 – 2013-03-09 07:33:04