View Full Version : js in iframe affecting anchors of main window, help please!

12-11-2009, 07:35 AM
First, apologies I'm a newbie with javascript. Here's the problem: I have javascript in an iframe that controls showing/hiding of divs. This works great, but after the javascript is executed it changes the behavior of anchor tags of the main window of the website (namely - links in the main window all open in new windows and not in the specified target iframe). I've searched and searched and looked up all sorts of things, rendering me a confused and frustrated fellow.

here's the script:

<script language="javascript">
function show(thechosenone) {
var newboxes = document.getElementsByTagName("div");

for(var x=0; x<newboxes.length; x++) {
name = newboxes[x].getAttribute("name");
if (name == 'newboxes') {
if (newboxes[x].id == thechosenone) {
newboxes[x].style.display = 'block';

else {
newboxes[x].style.display = 'none';

and in the body:

<a id="myHeader2" href="javascript:show('myDiv');" >click here to show div</a>

ANY help is greatly appreciated!

12-11-2009, 09:34 AM
A big error from the beginning. A DIV element may not bear a name. Use an id, not a name. The name attribute is to be used only within form's elements, images, links, anchors, frames and iframes. And the W3C recommendation is to use name on in case of form's elements.

12-11-2009, 10:02 PM
Thank you very much! That got rid of the funny behavior with the anchor links. Figured it was something simple, but I'm pretty unfamiliar with js.

Thank You!