Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parent.document.getElementById from iFrame to parent not working

Posted on 2013-05-14
9
Medium Priority
?
1,083 Views
Last Modified: 2013-05-14
An "onClick" call to a Javascript function to set the href of a button on a toolbar does not find the button when the call is made from an iFrame. The toolbar is in the main window.

alink = parent.document.getElementById('members_link');
or
alink = window.parent.document.getElementById('members_link');

This works when the link clicked is in the main window; it only fails when the link is in the iFrame.

I'm using Chrome, but also tested IE8.

Here's the menubar button:

<a id=members_link
      onClick=\"myLink='M'\"
      onmouseover=\"roll_over('members_button', 'images/menubar_Members_hi.jpg');\"
      onmouseout= \"roll_over('members_button', 'images/menubar_Members.jpg');\"
      href=\"directory.php\" target=main
      ><img class=menu_image src='images/menubar_Members.jpg' NAME=members_button></a>

The page only has this one iFrame.
0
Comment
Question by:wilri01
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39163931
try this from inside the iframe:
var alink = parent.$(parent.document).getElementById('members_link');

Open in new window

0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39164027
that might also work:
var alink = parent.$("members_link");

Open in new window

0
 

Author Comment

by:wilri01
ID: 39164032
sedgwick,
What do I need to do to use JQuery?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39164061
add this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Open in new window

0
 

Author Comment

by:wilri01
ID: 39164683
Sorry, but neither form works.
0
 
LVL 22

Accepted Solution

by:
Kim Walker earned 2000 total points
ID: 39165960
The parent document and iframe document must be in the same domain for the child iframe document to access the parent DOM. It is considered a security issue when the documents are in separate domains.
0
 

Author Comment

by:wilri01
ID: 39166437
Yes, I was aware of that, but it is the same domain.

BUT... you got me thinking.  I looked at how the link is being constructed for the button, and found it includes "www." and the URL I used to get ot the page left that off.

So I add "www." to the URL, and the Javascript code now works!

So the problem is, how can I tell if the user entered the "www.", or left it off?  Maybe use a relative HREF that doesn't include the domain name?

Maybe some kind of "rewrite" in Apache to add the "www." if it isn't entered?

God, I'm so happy to see this working at all!  THANK YOU SO MUCH!!!
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 39166502
Can you use a relative url in the button link?
0
 

Author Closing Comment

by:wilri01
ID: 39166892
The trick is to NOT include the "www." in the link.  Then the user can use, or not use, the "www." and it works.

I've been working on this off and on for almost a year.  It feels so good to see this work!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

618 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