Javascript:从弹出窗口中找到主页上的框架?
在下面的 Javascript 中,我必须不断从弹出页面中查找 mainFrame,有没有更好的方法来做到这一点?
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) {
}
}
}
}
}
In the following Javascript I have to keep finding the mainFrame from the Popup pages, is there a better way to do this?
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) {
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,有一种更干净(但不一定更好)的方法来做到这一点,假设您的插件始终驻留在名为
mainFrame
的元素内:Well, there's a cleaner (but not necessarily better) way to do that, assuming your plugin always resides inside an element called
mainFrame
: