Results 1 to 3 of 3

Thread: Unobtrusive javascript vs IE

  1. #1
    Join Date
    Dec 2006
    Location
    Twin Cities, MN
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unobtrusive javascript vs IE

    I'm having some problems with this unobtrusive javascript code.

    The javascript turns any link with class="popup" into a popup window... in firefox. In Ie, the links just run normally.



    Code:
    function buildPopups() {
        var popupLinks=document.getElementsByTagName('a'); //this tells the browser what tags to apply this to
        for (var i=0;i<popupLinks.length;i++)
        if (popupLinks[i].getAttribute("class")=="popup") { //if the link has a class of popup...
          popupLinks[i].onclick = function() { //when it's clicked on...
            openWindow(this.getAttribute("href"));	//run the openWindow() function
            return false; //kills the link so it wont fire normally
          }
        }
      }
      function openWindow(myURL) { //popup Function
        window.open(myURL,'popup');
      }
      window.onload=buildPopups; //run the popup function when the page loads

  2. #2
    Join Date
    Dec 2006
    Location
    Twin Cities, MN
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Alright, nevermind I got it working.

    It appears IE does not support the getAttribute() function, and will require me to use .className oh well.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It does support it, but you have to use getAttribute("className") rather than the standard getAttribute("class").
    However, there's really no reason to use getAttribute() here...
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •