micah
micah

Reputation: 8096

Prevent Browsers from Storing Current Page in History

I have a situation where I am opening a user-initiated popup window on my site that points to another site. Users shouldn't be accessing this page directly, and should only go to it under normal conditions if the site opens the popup window.

mysite.com -> mysite.myothersite.com

I noticed that the popup window page appears in history, and worse, appears in the address bar autocomplete suggestions.

This popup window is supposed to perform a one-time utility operation so it isn't useful for the user to have this in their history or autocomplete suggestions. However, users are accessing this popup directly (assuming by accident).

While I can't prevent anyone from doing this, i'm wondering if it's possible to have that page not record itself in the browsers history. It's messing with my analytics.

Upvotes: 0

Views: 1807

Answers (2)

Giorgian Borca-Tasciuc
Giorgian Borca-Tasciuc

Reputation: 1231

You might want to look at the history.replaceState functionality provided by the history API.

If the pop-up is served at the same location, simply do history.replaceState({}, 'mypage', '/my-page-address') in the JavaScript of the popup window. This way, it replaces the myothersite history entry with the mypage history entry, and instead of using mypage you can use the title and address of the original page.

Upvotes: 2

lluisrojass
lluisrojass

Reputation: 439

This is where state comes into play. Upon requesting the popup, place some indicator that allows the popup to open and then when the user requests it, clear that indicator. This type of information is usually done via backend session state, but can also be done completely via front end, but with with a reliability hit.

Upvotes: -1

Related Questions