francesca
francesca

Reputation: 587

Javascript Determine if page was refreshed or redirected from another page?

The question is pretty much in title.

Is there a way in Javascript to determine whether the page has been refreshed by user or loaded after redirecting from other website?

Upvotes: 3

Views: 4803

Answers (2)

JPG
JPG

Reputation: 378

Just to give a straight answer, as the answer above says you should

console.log(window.performance.navigation.type)

to see if the page was reloaded or redirected. 1 = reloaded and 0 = redirected.

Upvotes: 3

skav
skav

Reputation: 1460

performance.navigation.type will tell you if the page was reloaded, and some more info. Check out the docs here

Upvotes: 5

Related Questions