I get an undefined error in an iframe

I have an iframe below:

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

I try to stop the command below, but I keep getting an undefined error:

$('.upload_target').contentwindow is undefined

How can I fix this undefined error?

Below is the code:

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

});

+3
source share
1 answer

You get undefinedit because it contentWindowis native Javascript, and you use it in the jQuery collection, which does not have contentWindowa value. You must first get the source DOM object. Do this instead:

$('.upload_target').get(0).contentWindow
+5
source

All Articles