Results 1 to 2 of 2

Thread: Javascript compatibility Issue works in IE but not Firefox

  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript compatibility Issue works in IE but not Firefox

    Hello, I have a script that works fine in Internet explorer but does nothing in Firefox. Here is the code I am currently using:

    Code:
    <script type="text/javascript">
    
    var ExternalSite = "http://www.readtheticker.com/?userID="
    
    try {
    function GetMemberID () {
    var spans = document.getElementsByTagName('span');
    for (var i = 0; i < spans.length;){
    if (spans[i].innerText == "Member ID") {
    var MemberID = spans[i+1].innerText;
    var chkAdr = window.location.href;
    if (chkAdr.indexOf("?getID") != -1) {
    window.location = ExternalSite + MemberID;
    break;
    }
    }
    i++;
    }
    }
    if (window.BonaPage) BonaPage.addPageStateHandler(BonaPage.PAGE_PARSED, GetMemberID);
    } catch(err) {}
    </script>
    If anyone could help me out with the changes that need to be made I'd very much appreciate it!
    Last edited by jscheuer1; 02-24-2010 at 12:47 AM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Always check to be sure the properties and methods you are using are available in the browsers you want the script to run on.

    For instance with:

    Code:
    addPageStateHandler
    I've never heard of that one before. Unless it is defined elsewhere in code you haven't shown, it may be an IE proprietary function.

    By the same token:

    Code:
    innerText
    is (I believe) an IE only property. The closest cross browser equivalent would be:

    Code:
    innerHTML
    which will work in IE as well, and should do the job at least as far as that part goes.

    To check if a particular command is available in a particular browser, Google may often be used to research that.

    Also one can do something like:

    Code:
    alert(typeof object.property_or_method);
    Like with innerText, one may see it is not supported in Firefox with this test:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    onload = function(){alert(typeof document.getElementsByTagName('span')[0].innerText);};
    </script>
    </head>
    <body>
    <span>Hi</span>
    </body>
    </html>
    In IE it will give you:

    string

    In Firefox:

    undefined
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •