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.getElement ById('memb ers_link') ;
or
alink = window.parent.document.get ElementByI d('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('m embers_but ton', 'images/menubar_Members_hi .jpg');\"
onmouseout= \"roll_over('members_butto n', 'images/menubar_Members.jp g');\"
href=\"directory.php\" target=main
><img class=menu_image src='images/menubar_Member s.jpg' NAME=members_button></a>
The page only has this one iFrame.
alink = parent.document.getElement
or
alink = window.parent.document.get
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('m
onmouseout= \"roll_over('members_butto
href=\"directory.php\" target=main
><img class=menu_image src='images/menubar_Member
The page only has this one iFrame.
that might also work:
var alink = parent.$("members_link");
ASKER
sedgwick,
What do I need to do to use JQuery?
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>
ASKER
Sorry, but neither form works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!!
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?
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!
I've been working on this off and on for almost a year. It feels so good to see this work!
Open in new window