SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Very bizzare problem...

    Hey everyone.

    I'm having a lot of trouble with the typeof property in firefox. This problem is really wierd so I hope you take the time to read this thread.

    The problem only occurs when inspecting the document object's properties and only when using the typeof operator in the loop and only when using firefox. What the hell?

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function func(obj)
    {
    	var content=''
    	for (var i in obj)
    	{
    		if(typeof obj[i]=="object")
    		content+=i+"<br>";
    	}
    	return content
    }
    function func2()
    {
    document.getElementById("d").innerHTML=func(document)
    }
    </script>
    </head>
    <body>
    <button onclick="func2()">click</button>
    <div id="d"></div>
    </body>
    </html>
    1. Try swapping any different object in the "func" function beside document.
    2. Omit if(typeof obj[i]=="object").
    3. Use a different browser other than firefox.

    All of the following work. I'm very confused . Can someone please help me? All thoughts and suggestions are more than welcome!!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code Javascript:
    <html>
    <head>
    <script type="text/javascript">
    function func(obj)
    {
        var content=''
        for (var i in obj)
        {
    try { if (typeof obj[i] === 'object') content+=i+'<br>';} catch (e) {alert(i + ' '+ e)}
     
        }
        return content
    }
    function func2()
    {
    document.getElementById("d").innerHTML=func(document)
    }
    </script>
    </head>
    <body>
    <button onclick="func2()">click</button>
    <div id="d"></div>
    </body>
    </html>
    You'll see that the problem is not with typeof, it's with "domConfig", whatever that is. So you might just have to use try, catch for this.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Raffles and jimfraser, thank you for your help.


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
  •