URL重定向Javascript

URL重定向Javascript,javascript,Javascript,URL重定向Javascript? 我正在尝试用http://和提示符重定向输入的网址,直到找到http://为止,如果找到了,它会将其指向输入的网站 以下是我目前的代码: function enter() { var keepGoing = true; var email; while (keepGoing) { keepGoing = false email = prompt("Please Enter Website Addres

URL重定向Javascript? 我正在尝试用http://和提示符重定向输入的网址,直到找到http://为止,如果找到了,它会将其指向输入的网站

以下是我目前的代码:

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");
        }
    }
}
应将用户重定向到电子邮件中包含的URL,您可以设置:

使用location.href

window.location.href = email;

旁注:
keepGoing
变量是不必要的。
email.indexOf('http://')===-1
应该是
email.indexOf('http://')=0
,因为您必须验证http://是网站地址的第一部分
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://') != 0)
         {
            alert("Not valid Web Address");
            keepGoing = true;
         }

         //if nothing was entered
         else if(email == '')
         {
            var email = prompt("Please Enter Valid Web Address");
         }

         else
         {
            window.location.href=email;
         }       

    }
 }
window.location.href = email;