2012-11-11 42 views
0

我们创造这样添加JS来iframe的功能 - 道场

var iframe = dojo.io.iframe.create(generatedRequestId); 

一个iFrame我们希望有插入额外的像

功能printThis(){ window.print javascript函数(); }

iFrame中

,以便在父窗口我们可以称之为printThis从一些代码()函数一样

_setPrintExportCookieInterval: function(/**String*/requestId, /**function*/closePopup, /**String*/exportTypeId) { 
    //have the interval autoexpire after some amount of seconds 
    var count = 0; 
    var intervalMs = 2000; 

    var intervalId = self.setInterval(function() { 
     var reportCookie = dojo.cookie(requestId); 
     if(reportCookie || count > 300000) { //5 mins 
      //if there's a status failure, don't close the window 
      if(reportCookie == "success") { 
       //console.debug(exportTypeId); 
       if(exportTypeId == PRINT) { 
        var iframe = dojo.byId(requestId); 
        iframe.printThis(); 
       } 
       closePopup(); 
      } else { 
       console.debug("print/export request returned with nonstandard status " + reportCookie); 
      } 
      window.clearInterval(intervalId); 
      //delete the cookie 
      dojo.cookie(requestId, null, {path: "/", expires: -1}); 
      //destroy the iframe 
      //dojo.destroy(dojo.byId(requestId)); 
     }; 
     count+=intervalMs; 
    }, intervalMs); 

    return intervalId; 
}, 

-is这可能吗?我知道dojo.io.iframe.create(generatedRequestId)需要第二个参数,这个参数是在onload时执行的代码 - 但不一定是在iframe加载后可以调用的函数?

感谢您的任何建议。

回答

1

当您在浏览器JavaScript中声明“全局”变量或函数时,该变量作为window对象的属性可用。如果iframe来自同一个源,则可以通过iframe的contentWindow属性访问其window对象。

iframe.contentWindow.printThis();