Skip to content

Instantly share code, notes, and snippets.

@sdennler
Created September 30, 2015 12:36
Show Gist options
  • Save sdennler/4d04da7ff2f6c5eb60bc to your computer and use it in GitHub Desktop.
Save sdennler/4d04da7ff2f6c5eb60bc to your computer and use it in GitHub Desktop.
Open links to sites (who set X-Frame-Options: SAMEORIGIN) in a new window if the current site is loaded in a frame.
function inFrame() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
window.onload = function(){
if(inFrame()){
var anchors = document.getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
if (anchors[i].href.match(/xing|linkedin/)) {
anchors[i].setAttribute('target', '_blank');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment