Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Redirect Javascript [duplicate]

Tags:

javascript

URL Redirect Javascript? I have am trying to redirect an entered web address with a http:// and prompt until a http:// is found and if it is found it will direct it to the website that is entered.

Heres my code so far:

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");
        }
    }
}
like image 344
user2132849 Avatar asked Mar 09 '13 07:03

user2132849


People also ask

How do I redirect a clicked button?

The first way through which you can redirect from one page to another is by clicking a button. You can use a form for this purpose. The form tag in HTML has an attribute action where you can give the URL of the webpage, where you want the form button to redirect. The form tag also has another attribute method.

How do I redirect to another page in HTML?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

What is redirect script?

A JavaScript redirect is used to instruct a browser to load another URL. An example of what a JavaScript redirect may look like when we're sending visitors to https://www.contentkingapp.com/ after rendering the page: <script>window.location.replace("https://www.contentkingapp.com/");</script>


1 Answers

use location.href

window.location.href = email;
like image 96
Tim Sommer Avatar answered Nov 15 '22 21:11

Tim Sommer