1

I have this

authnav='<li class="last"><a href="auth/login">login</a></li>'+
  '<li><a href="auth/create_account">create account</a></li>';

It works fine in Firefox, but Internet Explorer gives me an "Error: Object doesn't support this property or method" I'm mystified - what could be going on here?

There's a comment line above the offending line, could that possibly be making a difference?

//authnav='<li class="last"><a href="auth/login">login</a></li>';

Check out the page yourself at http://www.imagineelection.com. I want two little links, "login" and "create account", to appear on the top right of the page.

Thanks!

2 Answers 2

4

The problem arises in this function as IE allows you to reference document.getElementById("authnav") as authnav and then gets upset when you assign it a string. Maybe declaring a local variable explicitly with var authnav will work or is it intended to be a global variable?

function add_auth_nav() {
    name = get_cookie("name");
    candidate = get_cookie("candidate");
    if (name) {
        authnav = '<li class="last"><a href="auth/logout">logout</a></li>';
        if (candidate) {
            authnav = authnav + '<li><a href="edit/candidate/' + candidate + '">edit profile</a></li><li><a href="profile/' + candidate + '">view profile</a></li>'
        }
        authnav = authnav + "<li>" + name.replace(/\+/g, " ") + "</li>"
    } else {
        authnav = '<li class="last"><a href="auth/login">login</a></li><li><a href="auth/create_account">create account</a></li>'
    }
    document.getElementById("authnav").innerHTML = authnav
}
Sign up to request clarification or add additional context in comments.

4 Comments

This makes sense. Is there any way I can explicitly cast authnav to be a string for now?
Just needed to run it through a reformatter so I could see what was happening. In the function I have just added to my post can you declare a local variable with "var authnav" so it doesn't think you are referring to the document element of that name? (Or maybe rename it to something else to avoid confusion - Unless is it intended to be global and declared somewhere else??)
I declared it with a local scope and that solved everything - thanks again.
name and candidate need to be declared var too, otherwise you get accidental globals, which leads to weird, difficult-to-debug errors. Always use var, even for globals; it avoids all these problems and is compulsory in ECMA262-5's new ‘strict mode’.
0

Results reproduced. Can you substitute the ie_scripts.min.js file with the original and check if it still fails...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.