Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.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 调用iframeJS类_Javascript_Iframe_Mootools - Fatal编程技术网

Javascript 调用iframeJS类

Javascript 调用iframeJS类,javascript,iframe,mootools,Javascript,Iframe,Mootools,我正处于这种情况 index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" con

我正处于这种情况

index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="mootools.js"></script>
<script>
window.addEvent('domready', function() {

 var b=document.createElement('iframe');
 b.src="about:blank";
 b.style.height="0px";
 b.style.width = "0px";
 b.style.visibility="hidden";
 b.style.border="none";
 b.id = "my_frame";
 b.src="about:blank";
        var headID = document.getElementsByTagName("head")[0];
 headID.appendChild(b);
 var val = '<html><head>';
        val += '<scr' + 'ipt type="text/javascript" src="test.class.js"></scr' + 'ipt>';

        val += '</head><body></body></html>';
        var doc = b.contentWindow || b.contentDocument;

        if (doc.document){
            doc = doc.document
        }

        doc.open();
        doc.write(val);
        doc.close();
});
</script>
</head>
<body>
<div id="main"></div>
<script>var a = new Test();</script>
<script>a.doSomething();</script>
</body>
</html>
可以将测试类注入父窗口,而不使用类似于
parent.frames[“my_frame”].func()的东西?我只需要使用这种方式来调用类:

<script>var a = new Test();</script>
<script>a.doSomething();</script>
var a=新测试();
a、 doSomething();

这样的事情不应该奏效吗

var a = new parent.frames["my_frame"].Test();
a.doSomething();

这应该行得通,但我希望使用干净的代码,而不使用parent.frames[“my_frame”]。。。有办法吗?
var a = new parent.frames["my_frame"].Test();
a.doSomething();