3 ms·
I'd like to see a mechanism to pass data to a page in the URL once, but have it discarded such that the URL the user sees and the URL used upon refresh lacks it
by TazeTSchnitzel 14y ago
I'd like to see a mechanism to pass data to a page in the URL once, but have it discarded such that the URL the user sees and the URL used upon refresh lacks it. This would be nice for all sorts of things:
* That pesky analytics stuff (rel= on YouTube for instance) which you don't want to re-send on refresh or when someone passes on the URL to someone else (because now your data is inaccurate)
* Error messages specified by URL parameters (we only want to show them once)
* URL parameters containing secrets allowing someone to access a page (we don't want to accidentally pass them on)
etc.
- knome 14y agoSomething like a POST request?
- TazeTSchnitzel 14y agoYes, but it would become a GET request were you to refresh or go back.
- justincormack 14y agoYou can use pushstate to do this in modern browsers.
- TazeTSchnitzel 14y agoI don't really want to add it to the user's history, though. Breaking the back button is bad.
- duncans 14y agoIn that case you use `history.replaceState()`, or just plain old `window.location.replace('url')`
- TazeTSchnitzel 14y agoWell, the latter would cause a reload, but the former sounds good. I'll try it, thanks!