防止网页嵌入
try{ top.location.hostname; //表明不存在跨域(或者未使用框架),就不采取操作 if (top.location.hostname != window.location.hostname) { //兼容Chrome浏览器 top.location.href =window.location.href; } }catch(e){ top.location.href = window.location.href; //表明存在跨域,就对top对象进行URL重导向 }
当前框架和顶层框架的域名不相同时禁止嵌入
转自:http://www.ruanyifeng.com/blog/2010/08/anti-frameset_javascript_codes_continued.html