www.webdeveloper.com
Results 1 to 5 of 5

Thread: javascript detect element as null or undefine

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    90

    javascript detect element as null or undefine

    Hi, I have the following script in the bottom of my page:
    Code:
    <script type="text/javascript">
    	if (navigator.appName.indexOf('Microsoft Internet Explorer')!=-1){
    		document.getElementById("fm_banner-diyur-plus1_704354692").style.top="81px";
    	}	
    </script>
    I also have an object with the exact id, before this line of code:
    Code:
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    			id="fm_banner-diyur-plus1_704354692"
    			class="flashmovie"
    			width="673"
    			height="138">
    	<param name="movie" value="http://barzilaymor.co.il/diur-plus.co.il/wp-content/uploads/2012/03/banner-diyur-plus1.swf" />
    	<!--[if !IE]>-->
    	<object	type="application/x-shockwave-flash"
    			data="http://barzilaymor.co.il/diur-plus.co.il/wp-content/uploads/2012/03/banner-diyur-plus1.swf"
    			name="fm_banner-diyur-plus1_704354692"
    			width="673"
    			height="138">
    	<!--<![endif]-->
    		
    <p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
    
    	<!--[if !IE]>-->
    	</object>
    	<!--<![endif]-->
    </object>
    And this code is before the script.

    Yet when I load the page:
    http://barzilaymor.co.il/diur-plus.co.il/

    When I load it in IE 9 I get following message:
    SCRIPT5007: Unable to get value of the property 'style': object is null or undefined
    diur-plus.co.il, line 487 character 3
    How come?

    After all I do have an element with the id of fm_banner-diyur-plus1_704354692?

    and why would it have an style property?
    After all, all element have supposed to have style property?

  2. #2
    Join Date
    Feb 2011
    Posts
    90
    I have changed my script, now it is:
    Code:
    document.getElementsByTagName('object')[1].style.top="81px";
    when I load it in IE, I still get:
    diur-plus.co.il
    SCRIPT5007: Unable to get value of the property 'style': object is null or undefined
    diur-plus.co.il, line 487 character 3
    but when I run it from the console, it does work.

    Why is that?

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,265
    Is your object positioned ? Without a position:absolute or relative for the flashmovie class your object can't be positioned !

  4. #4
    Join Date
    Jan 2011
    Posts
    117
    You are confusing IDs with Name properties

    Since element IDs are supposed to be a unique accessory-thing across the whole of the document -(meaning) only one ID may correspond to a certain person in the whole world -otherwise that ID is no ID at all; it's a useless crap; a forgery; and simply doesn't qualify for an ID anymore: the answer is you should learn more on the fundamental notions that apply far beyond this digital corner of the world!

  5. #5
    Join Date
    Jan 2011
    Posts
    117
    But, you can do yourself a cross-browser favor with a proper code like:
    Code:
    <object width=300 height=150 
    id=fm_banner-diyur-plus1_704354692
    data=http://barzilaymor.co.il/diur-plus.co.il/wp-content/uploads/2012/03/banner-diyur-plus1.swf>
    </object>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles