Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript:从弹出窗口在主页上查找框架?_Javascript_Asp.net_Frames - Fatal编程技术网

Javascript:从弹出窗口在主页上查找框架?

Javascript:从弹出窗口在主页上查找框架?,javascript,asp.net,frames,Javascript,Asp.net,Frames,在下面的Javascript中,我必须不断从弹出页面中查找大型机,有更好的方法吗 function sendRefreshMessage(data) { var myObj = null; myObj = document.getElementById('slPlugin'); if (null != myObj) { try { //perform operation on myObj } catch (err)

在下面的Javascript中,我必须不断从弹出页面中查找大型机,有更好的方法吗

function sendRefreshMessage(data) {
    var myObj = null;
    myObj = document.getElementById('slPlugin');
    if (null != myObj) {
        try {
            //perform operation on myObj
        } catch (err) {
        }
    }
    else {
        if (null != top.opener.top.mainFrame) {
            myObj = top.opener.top.mainFrame.document.getElementById('slPlugin');
            if (null != myObj) {
                try {
                    //perform operation on myObj
                } catch (err) {
                }
            }
        }
        else {
            myObj = top.opener.top.opener.top.mainFrame.document.getElementById('slPlugin');
            if (null != myObj) {
                try {
                    //perform operation on myObj
                } catch (err) {
                }
            }
        }
    }
}
好吧,有一种更干净(但不一定更好)的方法可以做到这一点,假设您的插件总是驻留在名为
大型机
的元素中:

function findPlugin(container)
{
    var plugin = null;
    if (container.mainFrame != null) {
        plugin = container.mainFrame.document.getElementById('slPlugin');
    }
    if (plugin == null && container.opener != null) {
        plugin = findPlugin(container.opener.top);
    }
    return plugin;
}

function sendRefreshMessage(data)
{
    var plugin = findPlugin(window.top);
    if (plugin != null) {
        try {
            // Perform operation on `plugin`.
        } catch (err) {
            // Please avoid empty catch blocks, they're evil.
        }
    }
}

我只有空的catch块,因为如果插件上的操作失败,我会得到一个JavaScript错误。