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");
}
}
}
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.
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.
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>
use location.href
window.location.href = email;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With