Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    js in iframe affecting anchors of main window, help please!

    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';
    }
    }
    }
    }
    </script>

    and in the body:

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

    ANY help is greatly appreciated!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •