Created
February 16, 2016 20:22
-
-
Save thelinuxlich/66b2e230a584bd4e253a to your computer and use it in GitHub Desktop.
getHref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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