Richie
Richie

Reputation: 5199

Jquery error --> Permission denied to access property document

I am using jquery in my web application and working with an iframe to show an application hosted on the same websphere server. Through the following code I am able to achieve an automatic login into the web application showing in the iframe....

JSP

<form:form id="posManagerLoginForm" 
    action="${posManagerUrl}" 
    target="posManagerFrame" 
    method="post" 
    class="ym-form whitenopadding">

<input type="hidden" name="user_name" value="myusername" />
    <input type="hidden" name="password" value="mypassword" />

</form:form>

<div class="ym-gbox">
    <iframe id="posManagerFrame" name="posManagerFrame" class="posManagerFrame"></iframe>                                          
</div>

JS

$().ready(function() {   
    $("#posManagerLoginForm").submit();
}); 

So far so good but now I am now trying to change the JS to be able to get the content in the iframe after the login has happened i.e. after form submit.

$().ready(function() {
    $("#posManagerLoginForm").submit(function(e){
        e.preventDefault();        
            this.submit();          
            var iframe = $("#posManagerFrame").contents();        
            return true;
    });
    $("#posManagerLoginForm").trigger("submit");   
});

As you can see I register a function for form submit and try and trigger the function on load. I have two issues....

  1. I get a Permission denied to access property document error when trying to get contents of iframe.
  2. While the .trigger("submit") statement does cause my function to execute, it appears to submit the form and then trigger the function. I am trying not to submit the form until the this.submit() statement.

Does anyone know where I am going wrong?

I have posted a couple of questions already this morning. Sorry about that. Thanks for your help.

Upvotes: 0

Views: 10694

Answers (1)

Alex Shilman
Alex Shilman

Reputation: 1547

This is forbidden due to cross domain origin. You can only get content of iframe from the same domain you are on.

Upvotes: 2

Related Questions