Link to home
Start Free TrialLog in
Avatar of wilri01
wilri01

asked on

parent.document.getElementById from iFrame to parent not working

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.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

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

Open in new window

that might also work:
var alink = parent.$("members_link");

Open in new window

Avatar of wilri01
wilri01

ASKER

sedgwick,
What do I need to do to use JQuery?
add this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Open in new window

Avatar of wilri01

ASKER

Sorry, but neither form works.
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wilri01

ASKER

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!!!
Can you use a relative url in the button link?
Avatar of wilri01

ASKER

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!