开发者

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.o开发者_运维百科nload = 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?


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.


unless the URL you are opening is the same domain, you do not have access to the newly created window object.


Try opening the window first with an empty URL, then performing the operation/attaching the handler, and then loading the content (mywin.location = ...).


Try trigger function

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜