Setting OnLoad event for newly opened window in IE6

前端 未结 6 460
天涯浪人
天涯浪人 2021-01-21 06:40

I need to set the onload attribute for a newly popped-up window. The following code works for Firefox:



        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 06:53

    onload is a property if window objects, not body elements, despite what the HTML attribute might lead you to believe. This is the reference:

    printwindow.onload
    

    However, in this context you can't pass it a string of JavaScript - you need to hand it a function. So, the full script like would look like this

    printwindow.onload=function(){self.print();}
    

    Now, putting it all together

    try it
    

    HOWEVER! This will not work for you for the URL "www.google.com". The browser security model prevents parent windows from accessing the window objects of child windows, UNLESS they both reside @ the same domain name.

提交回复
热议问题