Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created February 16, 2016 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxlich/66b2e230a584bd4e253a to your computer and use it in GitHub Desktop.
Save thelinuxlich/66b2e230a584bd4e253a to your computer and use it in GitHub Desktop.
getHref
var urlencode = function(str) {
return encodeURIComponent(str)
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/!/g, '%21')
.replace(/\*/g, '%2A')
.replace(/~/g, '%7E');
},
getHref = function() {
var href = '';
try {
href = window.top.location.href;
} catch (e) {
if (window.parent) {
try {
href = window.parent.location.href;
} catch (e2) {
href = '';
}
}
}
if (href === '') {
href = window.location.href;
}
if (href === '') {
href = document.location.href;
}
return urlencode(href);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment