-1

I'm trying to fire a click event When web page loaded inside an iframe, but it doesn't seem to be working.

$(function(){
    $('#iframe').load(function(){

        var iframe = $('#iframe').contents();

        iframe.find("#btnSubmit").click(function(){
               alert("test");
        });
});

});

When i am trying to using this code i am getting the error.

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a frame with origin "https://pptform.state.gov".  The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "https". Protocols must match.

Please tell me how to resolve this issue. Thanks in advance

Arash Milani
  • 5,852
  • 2
  • 38
  • 45
Umesh Saraswat
  • 445
  • 1
  • 7
  • 17
  • 1
    What exactly are you trying to do? Cannot you just link directly to specific page? Anyway, looks like you are trying to fool in some way an US gov site, sounds like a bad idea... – A. Wolff Aug 13 '15 at 08:55

1 Answers1

2

You cannot do that if the domains of the iframe and your parent site do not match, which they don't seem to in this case. Allowing it would be a big security risk.

If both sites are under your control, you can communicate across the iframe border using postMessage or using some URL hash hacks. However, if they are not under your control, there isn't much you can do about it.

Community
  • 1
  • 1
musically_ut
  • 33,232
  • 8
  • 87
  • 102
  • is there is now way to do that. – Umesh Saraswat Aug 13 '15 at 08:49
  • 1
    @UmeshSaraswat Which part of this answer don't you understand? – A. Wolff Aug 13 '15 at 08:51
  • i understand what you have written. but i want to ask u is there any way to do that. – Umesh Saraswat Aug 13 '15 at 08:56
  • @UmeshSaraswat So you don't understand this answer... You could proxify it website page server side but you are really asking for trouble imho – A. Wolff Aug 13 '15 at 08:57
  • @UmeshSaraswat As long as the users are accessing the website using secure (read: latest) browsers or web-views, and the other website isn't under your control (and the Passport application site probably isn't), no, there isn't anything you can do. – musically_ut Aug 13 '15 at 08:57