[英]I get an undefine error in iframe
I have an iframe below: 我下面有一个iframe:
<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe>
I am trying to stop a command below but I keep getting an undefined error: 我试图在下面停止命令,但我一直收到一个未定义的错误:
$('.upload_target').contentwindow is undefined
How can I fix this undefined error? 如何修复此未定义的错误?
Below is code: 以下是代码:
$(".uploadbutton").click(function() {
$(".upload_target").contentWindow.stop(); //for anything but IE
$(".upload_target").contentWindow.document.execCommand("Stop"); // for IE
return stopImageUpload();
}); });
You get undefined
because contentWindow
is native Javascript and you're using it on a jQuery collection, which doesn't have contentWindow
as a value. 你得到
undefined
因为contentWindow
是本机Javascript,你在jQuery集合上使用它,它没有contentWindow
作为值。 You have to get the original DOM object first. 您必须先获取原始DOM对象。 Do this instead:
改为:
$('.upload_target').get(0).contentWindow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.