9

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");
        }
    }
}
4

3 回答 3

3

使用 location.href

window.location.href = email;
于 2013-03-09T10:17:40.960 回答
1
window.location.href = email;

应该将用户重定向到包含在email

于 2013-03-09T07:26:52.407 回答
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;
         }       

    }
 }
于 2013-03-09T07:29:06.487 回答