4

I have an iframe below:

<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();

});

user1333290
  • 143
  • 1
  • 3
  • 9

1 Answers1

8

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. You have to get the original DOM object first. Do this instead:

$('.upload_target').get(0).contentWindow
elclanrs
  • 92,861
  • 21
  • 134
  • 171
  • Hi, I am not getting the error which is great but can I ask you one last question. the code above was to stop a file uploading but this did not seem to work. Do you know how to stop a file uploading by jquery when user clicks on the .uploadbutton? – user1333290 Apr 16 '12 at 00:55
  • @user1333290 we have no way of answering your second question without knowing what `uploadbutton` is. – jbabey Apr 16 '12 at 02:23
  • .uploadbutton is a class given to a normal button (input type='button class='uploadbutton') – user1333290 Apr 16 '12 at 02:31