【问题标题】:I get an undefine error in iframe我在 iframe 中收到未定义的错误
【发布时间】:2012-04-16 08:49:54
【问题描述】:

我在下面有一个 iframe:

<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe>

我正在尝试停止下面的命令,但我不断收到未定义的错误:

$('.upload_target').contentwindow is undefined

如何解决这个未定义的错误?

下面是代码:

   $(".uploadbutton").click(function() {
          $(".upload_target").contentWindow.stop(); //for anything but IE
          $(".upload_target").contentWindow.document.execCommand("Stop"); // for IE
  return stopImageUpload();

});

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    您会得到undefined,因为contentWindow 是本机Javascript,并且您在没有contentWindow 作为值的jQuery 集合上使用它。您必须首先获取原始 DOM 对象。改为这样做:

    $('.upload_target').get(0).contentWindow
    

    【讨论】:

    • 嗨,我没有收到错误消息,这很好,但我可以问你最后一个问题。上面的代码是停止文件上传,但这似乎不起作用。当用户点击 .upload 按钮时,你知道如何停止 jquery 上传文件吗?
    • @user1333290 我们无法在不知道uploadbutton 是什么的情况下回答您的第二个问题。
    • .uploadbutton 是一个赋予普通按钮的类(输入类型='button class='uploadbutton')
    猜你喜欢
    • 2022-06-27
    • 2022-11-19
    • 2020-12-30
    • 1970-01-01
    • 2020-11-17
    • 2022-07-26
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    相关资源
    最近更新 更多