URL重定向Javascript

时间:2013-03-09 07:23:26

标签: javascript

网址重定向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");
        }
    }
}

3 个答案:

答案 0 :(得分:3)

使用location.href

window.location.href = email;

答案 1 :(得分:1)

window.location.href = email;

应将用户重定向到email

中包含的网址

答案 2 :(得分:0)

您可以设置window.location.href

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;
         }       

    }
 }
相关问题