SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.getElementsByTagName

    Hi everybody
    Please, I'm new here and I need help.
    Why this js does not work in Firefox (fine in IE) ?
    I dont know so much but I need solve.
    HTML Code:
    <script type="text/javascript">
    function changeLink() {
    var links = document.getElementsByTagName("a");
    for(var i=0;i<links.length;i++) {
    links[i].onclick="popup='no'";
    }
    }
    </script>
    </head>
    <body onload="changeLink();" class="f-default style2">
    Thanks in advance.

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what exactly this script do?
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks by reply.

    I need replace this:

    <a

    with this:

    <a onClick='popup="no"'

  4. #4
    SitePoint Enthusiast benno23's Avatar
    Join Date
    May 2008
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont know if this helps but here is another method of dynamically assigning the onClick event:

    Code:
    <script type="text/javascript">
    function changeLink() {
    	var links = document.getElementsByTagName("a");
    
    
    	for(var i=0;i<links.length;i++) {
    
    		links[i].onclick = function() { alert('I have been clicked')};
    	}
    }
    </script>

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Benno23 (both 23 )

    I see but i need change phisically the tag a ... adding this text onClick='popup="no"'

    I mean

    <a

    must be

    <a onClick='popup="no"'

  6. #6
    SitePoint Enthusiast benno23's Avatar
    Join Date
    May 2008
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well ... this works in Firefox. I'm on a MAC right now so I am not 100% sure this will still work back on IE. Give it a try:
    Code:
    <script type="text/javascript">
    function changeLink() {
    	var links = document.getElementsByTagName("a");
    
    
    	for(var i=0;i<links.length;i++) {
    
    		links[i].setAttribute("onclick", "popup='no'");
    	}
    }
    </script>

  7. #7
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are doing any changes int eh Java script then it will definately not make the changes in the View Source. These are made in the runtime and kept in the memory itself.

    Quote Originally Posted by panky23 View Post
    Thanks Benno23 (both 23 )

    I see but i need change phisically the tag a ... adding this text onClick='popup="no"'

    I mean

    <a

    must be

    <a onClick='popup="no"'
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everybody
    I see now

  9. #9
    SitePoint Enthusiast benno23's Avatar
    Join Date
    May 2008
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to view the source after you have changed the DOM with javascript you can use the web developer toolbar in firefox. Or this method for IE.

  10. #10
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to set the variable popup value to 0?

    Then try:

    Code JavaScript:
    function changeLink() {
    	var links = document.getElementsByTagName("a");
     
    	for(var i=0;i<links.length;i++) {
     
                  previousClickEvent = links[i].onclick ? links[i].onclick : null;
                  links[i].onclick = function(){
                         if(previousClickEvent){
                                   previousClickEvent();
                         }
                         popup = 0;
                  }
    	}
    }

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, exactly !!!

    Very very thanks


Bookmarks

Posting Permissions

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