Cenarius
Cenarius

Reputation: 225

Replace whole page in browser

I would like to ask how to replace full address of page in browser.

Example:

www. myWebsite .com -> www. superWebsite .com

Is it possible to use JavaScript or Ajax or whatever?

It's for my education and own purpose on my laptop out of curiosity.

Upvotes: 0

Views: 77

Answers (2)

Lahiru Jayakody
Lahiru Jayakody

Reputation: 5410

You can't change the value in address bar without navigating to that website. You can navigate to another page using many of ways.

var domain= "www.superWebsite.com"
var url = "http://" + domain
// use one of following ways
location = url
window.location = url 
window.location.href = url    // will work in most browsers
window.location.assign(url)
window.location.replace(url)  // back button will not redirect to current page after navigating to `url`

Upvotes: 1

Saurabh Agrawal
Saurabh Agrawal

Reputation: 7739

If I understand correctly, then I think you want to navigate from one page to another,

For this you should use

var myWebLink = 'www.superWebsite.com'

window.location.href = myWebLink;

It will navigate to www. superWebsite .com

Upvotes: 2

Related Questions