Saad
Saad

Reputation: 53919

Switching to a different page without reloading?

I need help figuring out how to load a different page into the current browser window. Basically, I made a home screen page and the actual game page.

Home page: http://jsfiddle.net/f7mL6wfu/2/

Game page: http://jsfiddle.net/brwsrr6s/

I want the button on the home page to change the current page to the game page. Is there a way to make this happen? So, in my home page, I need something like this:

var btn = document.getElementById('btn');
btn.addEventListener('click', function() {
    // Code to load a different page into the window theoretically goes here
});

Any help would be very much appreciated.

Upvotes: 1

Views: 75

Answers (1)

seanlevan
seanlevan

Reputation: 1415

This is easy, use the JavaScript function window.location, as in the following code:

window.location="http://www.example.com/";

This code snippet uses the Locaion Object, which contains information about the current URL. It can be accessed through the window.location property.

Click the checkmark next to this answer if it was informative or helped you in any manner.

Upvotes: 1

Related Questions