JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 2nd, 2009, 06:33 AM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 355 romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 1 h 57 m
Reputation Power: 45
GetElementsByTagName("script") doesn't work properly after an AJAX call in IE

The following code works well in both FF and IE

Code:
<div id="div1">
<script  type="text/javascript">
// somecode
</script>
</div>

 <script type="text/javascript">
 var scripts = document.getElementById("div1").getElementsByTagName("script");
 alert (+scripts.length);
 </script>



However if the contents of div1 obtains its innerHTML from an AJAX call then the first <script> tage is not found by getElementsByTagName("script") if there is no other HTML before the <script> tag.

Why does this happen?

Reply With Quote
  #2  
Old October 3rd, 2009, 11:15 AM
loonychune's Avatar
loonychune loonychune is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Location: Manchester, UK
Posts: 153 loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level)loonychune User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Days 15 h 6 m 31 sec
Reputation Power: 255
So you're doing something like this... ?

Code:
if(xmlhro.readyState == 4) {
  div1.innerHTML = xmlhro.responseText;
}


If that's the case, then the innerHTML property actually overwrites anything inside the dom object it is a property of.
Comments on this post
lnxgeek agrees!

Reply With Quote
  #3  
Old October 5th, 2009, 10:40 PM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 355 romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 1 h 57 m
Reputation Power: 45
The the response text actually contains the <script> tags. So I am not looking for tags that have been overwritten but script tags that have actually been returned by Ajax calls.

Reply With Quote
  #4  
Old October 5th, 2009, 10:43 PM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 355 romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level)romario User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 1 h 57 m
Reputation Power: 45
I am actually having to do something like this to solve the problem!!


Code:
if(xmlhro.readyState == 4) {
  div1.innerHTML = "<span style=\"display: none\">anything</span>" +xmlhro.responseText;
}


That just seems very wrong! If I dont do it then the .getElementsByTagName("script"); doesnt seem to find the first <script> tag if it has nothing before it.

Reply With Quote
  #5  
Old October 6th, 2009, 06:09 AM
Winters Winters is offline
Bad Coder
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,547 Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level)Winters User rank is General 21st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 4 h 27 m 5 sec
Reputation Power: 2372
__________________
[PHP] | [Perl] | [Python] | [Java] | [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > GetElementsByTagName("script") doesn't work properly after an AJAX call in IE


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap