简体   繁体   English

使用 jquery 将脚本添加到 iframe

[英]Adding scripts to an iframe using jquery

I am generating an iframe within a jquery dialog box but am having trouble loading some scripts within it.我在 jquery 对话框中生成 iframe,但在其中加载一些脚本时遇到问题。

function showDialog() {
       $("#divID").dialog("open");
       $("#modalIframeID").attr("src", "/staff/somepage");
      return false;
}
$(document).ready(function() {
    $("#divID").dialog({
        autoOpen:false,
        modal:true,
        height:500,
        width:960,
        closeOnEscape:true,

    });
});

I tried adding them through a load event but havent had any success.我尝试通过加载事件添加它们,但没有任何成功。

function showDialog() {
    $("#modalIframeID").load(function()
    {
        //load scripts here
        $("#addFaci").formToWizard();
    });
    $("#divID").dialog("open");
    $("#modalIframeID").attr("src", "/staff/somepage");

    return false;
 }

Any suggestions would be appreciated.任何建议,将不胜感激。

Thanks,谢谢,

Tim蒂姆

If you have access to the file that is being loaded into the iframe you could just add the javascript code into that file and attach it to the document ready event.如果您有权访问正在加载到 iframe 的文件,您只需将 javascript 代码添加到该文件中并将其附加到文档就绪事件。

If not try reading this following article and see if it will help you out:)如果不尝试阅读以下文章,看看它是否会对您有所帮助:)

http://huuah.com/jquery-and-iframe-manipulation/ http://huuah.com/jquery-and-iframe-manipulation/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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