[英]JS function doesn't work in a window
我打开一个新窗口,需要在其上调用一个函数。 如果我在新窗口中编写$(document).ready内的函数,它可以工作,但是我想将其称为“正常”函数...我的代码:
var mywindow = window.open('', '', 'height=600,width=800');
mywindow.document.write('<html><head><title>My Title</title>');
mywindow.document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>');
mywindow.document.write('<script type="text/javascript" src="function.js"></script>');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.myFunction();
我得到“ mywindow.myFunction不是函数”
在作品上写函数...
mywindow.document.write('<script> $(document).ready(myFunction())</script>')
为什么? 调用该函数有什么问题?
var mywindow = window.open('', '', 'height=600,width=800');
mywindow.document.write('<html><head><title>My Title</title>');
mywindow.document.write('<script type="text/javascript" src="full host and path to js"></script>'); // see 1.
mywindow.document.write('</head><body >');
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.addEventListener('load', function() { // see 2.
mywindow.myFunction();
});
mywindow.document.close();
触发加载事件,然后只有此功能才可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.