开发者

TypeError: Result of expression 'printWindow' [undefined] is not an object

I'm trying to create hidden iframes in my page dynamically to load 3 other pages so that i can grab all the HTML and combine them into 1 in a new window.

However i'm stuck at this. tHe frames are created fine. But whenever the javascript runs to the part of

 var printWindow="";
 function openNewWindow()
 {
     printWindow = window.open("","");
     printWindow.document.open();
     p开发者_StackOverflow社区rintWindow.document.write(HTMLfromFrames);
     printWindow.document.close(); 
 }

i get this error: TypeError: Result of expression 'printWindow' [undefined] is not an object.

but if i generate a button to call this function seperately, it works fine. however i need it to run all in one click event

Anybody has any idea what's wrong? Thanks!


It looks to me like a scoping problem. The scope of your printWindow object ends when openNewWindow returns; in other words, the variable only exists inside that function and disappears as soon as the function ends. Remove the var to make the variable available globally (considered bad form) or declare the variable elsewhere in your code and make sure it's available to openNewWindow when it executes.


oh i solved it. SOmehow i declared as a global var then declare the obj earlier in the method. printWindow = window.open("",""); still not sure why i can't declare it after i dynamically create my iframes. Thanks for the help!:D

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜