简体   繁体   中英

using window.onload function

<script type="text/javascript">
function init() {
     document.write("www.sabah.com.tr opened..")
}
function start() {
var myWin = window.open("http://www.sabah.com.tr","_blank");
myWin.onload = init;  // i think the poroblem is here..
}
setTimeout(start, 5*1000);
</script>

i want to call init function when my new page loaded but there is a problem.. init function didnt call when page loaded.. so how can i call init function?

除非您打开的URL是同一个域,否则您无权访问新创建的窗口对象。

尝试首先使用一个空URL打开窗口,然后执行操作/附加处理程序,然后加载内容(mywin.location = ...)

There are several problems with that code:

  • The function will be run in the scope of the current page, not the newly opened page.

  • You can't use document.write after the page has loaded, that will scrap the page and replace it with the string specified.

  • If the page is loaded from a different domain, you can't access it in any way.

尝试触发功能

myWin.onload=$('#form_id').trigger('init');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM