dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Cannot set property of null (error only in Google Chrome)

  1. #1
    Join Date
    Jan 2010
    Posts
    1

    Cannot set property of null (error only in Google Chrome)

    I am using a script called ajax_load.js that defines a function, ajaxpage(), that allows a person to load the contents of an external page into a div item. I have it setup so I may use ajaxpage() to load pages with other div items in it. The problem is that I cannot reference the div items loaded by ajaxpage(). I have provided an example below to illustrate this. It was working fine in the prior version of Google Chrome and is still working fine in IE 8, IE 7, and Firefox. The version of Chrome I am currently using is 4.0.249.78

    Here is the example; All the files used in this example are listed below:

    74.54.95.210/~admin/js_test/ajaxtest.html
    74.54.95.210/~admin/js_test/ajax_load.js
    74.54.95.210/~admin/js_test/ajaxtest_external.html
    74.54.95.210/~admin/js_test/blank.png

    The breakdown of what is happening:

    ajaxtest.html is the primary file here. It loads ajax_load.js into it, which defines the ajaxpage() function.

    ajaxpage() works like this .. ajaxpage('external_page_name.file_ending', 'target_div_element');

    ajaxtest.html contains a div item with the id "sample_target". ajaxpage() is used to load the contents of ajaxtest_external.html into it, which is another div item with the id "sample_target_external".

    Here is where it gets complicated: Once the "sample_target_external" div is loaded by ajaxpage(), ajaxtest_external.html attempts to use javascript to set the innerHTML value of "sample_target_external". However, it does not work and the error comes up "Uncaught TypeError: Cannot set property 'innerHTML' of null"

    The function used to try and change the innerHTML value of "sample_target_external" is, load_text(), which is defined in ajaxtest.html

    If you want to see it all in action, load up the following url:

    74.54.95.210/~admin/js_test/ajaxtest.html


    This code was working just fine in the prior stable version of chrome, and still works properly in IE 8, IE 7, and Firefox without any errors (The version of chrome giving me problems is 4.0.249.78). Does anyone know how to go about fixing this? Is this something wrong with the latest version of chrome, or is this on my end? ANY help would be greatly appreciated. The site I am currently working on relies heavily on this working, and having to change things means altering several thousand lines of code.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    A quick test shows that Chrome throws this error if the element does not exist.
    I suspect, as you are using the image onload, that Chrome loads images before rendering the html.

Thread Information

Users Browsing this Thread

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

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