View Full Version : Element.update() and loadScripts...

24 Nov 2006, 2:10 PM
Turned out the regex still wasn't there. It was greedy in matching the ([\'\"]) pattern, and in the string <script src="foo" type="text/javascript"></script> if would extract the source as 'foo" type="text/javascript"'

Also, on the else side of the srcMatch, match[1] is always true for valid script tags - it's a string, but zero length, so I added a length check:

YAHOO.util.Event.onAvailable(id, function(){
var hd = document.getElementsByTagName("head")[0];
var re = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/img;
var srcRe = /\ssrc=[\'\"]([^\'\"]*)[\'\"]/i; // <------ this changed
var match;
while(match = re.exec(html)){
var srcMatch = match[0].match(srcRe);
if(srcMatch && srcMatch[1]){
var s0 = document.createElement("script");
s0.src = srcMatch[1];
}else if(match[1] && (match[1].length != 0)){ //<----- this changed too
var el = document.getElementById(id);
if(typeof callback == 'function'){

24 Nov 2006, 4:57 PM
Damn, I wish I would have found these before the release. That sucks.

25 Nov 2006, 1:28 AM
Well, I guess I should have tested with the src and type attributes the other way round when I did my initial testing too!

25 Nov 2006, 10:38 AM
In fact, the regex to extract the src should be


The "?" after the .* makes it reluctant rather than greedy, so it stops at the first occurrence of capture group 1 (' or ").

Obviously then, the src is in match[2]

25 Nov 2006, 4:23 PM
I'm ahead of ya. I didn't use the back reference but using it makes sense.

26 Nov 2006, 6:22 AM
In fact using the backreference method to delimit the src="" string, I'm sure you could get the script search for both src URLs and source code content back into one regex! Hours of fun for the geekly minded........ I'll have a play! :lol:

6 Dec 2006, 5:03 AM
ran into the same problem. wondering if the fix will make it's way into the rc4 or final 33 release? currently using rc3. thanks / matthew

6 Dec 2006, 5:46 AM
I'm not seeing the problem in RC3

8 Dec 2006, 12:04 AM

saw that the regular expression for srcRe was replaced between rc2 and rc3 but the src property gets set to blank if the srcMatch[1] item is pulled. had to pull srcMatch[2] instead (regardless of the order of script tag attributes).

9 Dec 2006, 7:08 AM
It should be 2, the 1st match is the quote. I will be doing a bug fix release to correct this and other rc3 bugs this weekend.

20 Apr 2007, 5:33 AM

i'm not sure if it's ok to post this here or in separate post.
i had my code this way:
<script language="javascript">var sLogo='<img src="images/logo.jpg">'</script>

so i think the code above first finds opening script and then the srcRe finds src from the variable sLogo, and this is wrong. I get an error. This is a bug right.

20 Apr 2007, 3:38 PM
<script type="text/javascript">var sLogo='<img src="images/logo.jpg">'</script>