Solved

Access Denied using iFrame with jQuery in IE

Posted on 2014-01-10
3
3,097 Views
Last Modified: 2014-01-10
I’m trying to access the html in an iFrame with jQuery. I’m getting Access Denied in IE 11 and it’s not working in other browsers. The jQuery code and the iFrame page reside on the same domain. Also, this is a Dnn site if that matters.

The code below is how I’m testing, just trying to change the color of a button.

Any suggestion?

Thanks!

JQuery Code:

var frm = $("iframe").contents();
frm.find(".ppButton").css("background-color","red")

Open in new window


iFrame Form Code:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="xxxx">
<table class="ppTable">
    <tr>
        <td>
            <select name="os0"  class="ppDropDown">
                <option value="Orange">Orange </option>
                <option value="Red">Red</option>
           </select>
        </td>
        <td>
            <input class="ppButton" type="submit" border="0" name="submit" value="Add to Cart" style="color: white;
                background-color: #FF8429; border: 1px solid #FF8429" />
        </td>
    </tr>
</table>
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif"
    width="1" height="1">
</form>

Open in new window

0
Comment
Question by:rcl58
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39772506
If the URL of the iframe is different from the parent page you cannot access it.

http://en.wikipedia.org/wiki/Same-origin_policy

Even if there is a slight difference in the iframe url e.g. www.mysite.com and the iframe url is mysite.com then they are different domains
0
 

Author Closing Comment

by:rcl58
ID: 39772706
That was it! There was not "www." on my iFrame URL. Thanks
0
 
LVL 58

Expert Comment

by:Gary
ID: 39772713
Must have been my psychic powers coming out.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question