防止iframe被别的网站引用


try{   top.location.hostname;  

 if (top.location.hostname != window.location.hostname) {

    top.location.href =window.location.href;  

 }

} catch(e){  

 top.location.href = window.location.href;

}

将这段代码放在ifame页面中,判断父页面的域名与iframe页面的域名是否一致,如果不一致就让父页面跳转到iframe的网址上去,以后不怕iframe被别的网站引用了。^-^

原文地址:https://www.cnblogs.com/learnings/p/8341629.html