Skip to content

Instantly share code, notes, and snippets.

@iiic
Forked from milo/fid-remove.js
Last active May 23, 2017 07:53
Show Gist options
  • Save iiic/016231fd4828d71654debda1ebd06a76 to your computer and use it in GitHub Desktop.
Save iiic/016231fd4828d71654debda1ebd06a76 to your computer and use it in GitHub Desktop.
Flash message _fid parameter remove.
(function (w) {
'use strict';
const TIMEOUT = 2000;
const FID_QSA = '_fid=';
function removeFid() {
var url = w.location.search.toString();
var fidPosition = url.indexOf(FID_QSA);
if (w.history && w.history.replaceState && fidPosition !== -1) {
var repairedUrl = url.substr(0, fidPosition) + url.substr(fidPosition + 10);
while ((repairedUrl.substr(repairedUrl.length-1) === '?') || (repairedUrl.substr(repairedUrl.length-1) === '&')) {
repairedUrl = repairedUrl.substr(0, repairedUrl.length-1);
}
w.history.replaceState({}, null, w.location.pathname.toString() + repairedUrl + w.location.hash);
}
return true;
}
w.addEventListener('beforeunload', removeFid);
setTimeout(removeFid, TIMEOUT);
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment