gpt4 book ai didi

javascript - 从子窗口中删除亲子关系

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:54:34 24 4
gpt4 key购买 nike

我正在处理旧开发人员的网站和代码。

这家伙写了一个 GLOBAL 打印函数,它基本上可以感知任何打开的新窗口(通过任何方法)和“href.match”是域名......如果需要,脚本然后应用打印样式表并且触发 window.print。

这一切都是通过每个页面上的全局脚本完成的,并包含一些其他功能。

我厌倦了为每个添加的页面写案例,我想逃避这个功能。此外,如果我确实为特定页面编写了 NOT 子句,则在子窗口中的域内打开的任何后续页面都将收到该打印功能。

有没有办法在这个新窗口中“破坏”继承?基本上是让这个窗口不是生成它的父窗口的子窗口?

    addEvent(window, 'load', function () {
var printBtn = document.getElementById('print-page');
if (window.opener && window.opener.location.href.match('domainnamehere')) {
var printCSS = document.createElement('link');
var a = document.getElementsByTagName('a');
printCSS.href = 'css/print.css'
printCSS.setAttribute('type', 'text/css');
printCSS.setAttribute('rel', 'stylesheet');
document.getElementsByTagName('head')[0].appendChild(printCSS);

for (var i = 0; i < a.length; i++) {
a[i].href="";
a[i].onclick = function () { return false; };
a[i].style.cursor = "default";
}

window.print();
} else if (printBtn){
printBtn.onclick = function () {
var printWindow = window.open(window.location, 'printwindow', 'resizable,width=800,height=800,scrollbars');

return false;
};
}
});

最佳答案

opener 属性提供对子窗口的访问权限,因此如果您想断开它,您只需将其设置为 null。执行此操作时,我总是在取消之前将其复制到另一个属性,以防您出于其他原因需要它...

if(bustInheritance) {
window.oldOpener = window.opener;
window.opener = null;
}

关于javascript - 从子窗口中删除亲子关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4961968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com