Skip to content

Instantly share code, notes, and snippets.

@tommyh
Created December 16, 2015 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyh/d59b926af789763d9b0e to your computer and use it in GitHub Desktop.
Save tommyh/d59b926af789763d9b0e to your computer and use it in GitHub Desktop.
var fakeWindow = {};
for(var key in window) {
if(key !== "location"){
fakeWindow[key] = window[key];
}
}
var fakeLocation = {};
for(var key in window.location) {
fakeLocation[key] = window.location[key];
}
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash"; // PUT the fake url here
fakeLocation.protocol = parser.protocol;
fakeLocation.hostname = parser.hostname;
fakeLocation.port = parser.port;
fakeLocation.pathname = parser.pathname;
fakeLocation.search = parser.search;
fakeLocation.hash = parser.hash;
fakeLocation.host = parser.host;
fakeLocation.href = parser.href;
fakeLocation.origin = parser.origin;
fakeWindow.location = fakeLocation;
(function(window){
debugger;
})(fakeWindow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment