UserSN
UserSN

Reputation: 1013

Javascript - Running a pushState script on pageload

I'm trying to run the following script on pageload so that it pushes the querystring value into the page onpageload not sure how to combine the two arguments.

window.history.pushState('{ }','','?semester=March');
return false;

window.onload = window.history.pushState('{ }','','?semester=March');
return false;

Upvotes: 0

Views: 158

Answers (1)

Sarah Groß
Sarah Groß

Reputation: 10879

You are currently assigning the result of executing the pushState() function (which is undefined) to window.onload. But you have to assign a callback function to it that will be triggered when the onload event fires.

window.onload = function() {
    window.history.pushState('{ }','','?semester=March');
}

Upvotes: 1

Related Questions