删除父母表单子窗口 [英] Remove parentage form child window

查看:83
本文介绍了删除父母表单子窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个旧开发者的网站和代码。

I am dealing with an old developer's site and code.

这个人写的GLOBAL打印功能基本上可以感知任何打开的新窗口(来自任何方法)和href.matches域名...脚本然后应用打印样式表,如果需要并触发window.print。

There is a GLOBAL print function the guy wrote that basically senses for any new window that opens (from any method) and "href.match"es the domain name... the script then applies a print stylesheet if need be and fires window.print.

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

This is all done from a global script that is on every page and houses some other functions.

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

I am tired of writing cases for each page added that I want to escape this function. Also if I do write a NOT clause for the certain page, any subsequent page opened within the domain in the child window will then receive that print function.

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

Is there a way to "bust" the inheritance in this new window? Basically to make this window NOT the child of the parent that spawned it?

    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;
        };
    }
});


推荐答案

开启者 property是允许访问子窗口的内容,因此如果要断开连接,则只需将其设置为null即可。这样做的时候,我总是将它复制到另一个属性,然后因为其他原因需要它而无效...

The opener property is what gives access to the child window, so if you want to disconnect it all you have to do is set it to null. When doing this, I always copy it to another property before nullifying in case you need it for other reasons...

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

这篇关于删除父母表单子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆