URL Redirect Javascript



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

use location.href

window.location.href = email;
window.location.href = email;

应该将用户重定向到email

中包含的URL。

可以设置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;
         }       
    }
 }

最新更新