2013-03-09 11 views
9

यूआरएल रीडायरेक्ट जावास्क्रिप्ट? मैं एक 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"); 
     } 
    } 
} 
+0

साइड नोट: 'keepGoing' चर बल्कि अनावश्यक है। – JJJ

+1

'email.indexOf ('http: //') === -1'' email.indexOf ('http: //') होना चाहिए! = 0', क्योंकि आपको http: // को मान्य करना होगा पहला भाग है वेबसाइट पते का –

उत्तर

1
window.location.href = email; 

यूआरएल email

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

    } 
} 
3

उपयोग location.href

window.location.href = email; 
संबंधित मुद्दे