Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#381 closed enhancement (wontfix)

Enhance to execute embedded and linked script files

Reported by: [email protected] Owned by: alex
Priority: high Milestone:
Component: General Version: 0.2
Keywords: Cc:
Blocked By: Blocking:


Add an option into to execute any javascript in between <script></script> tags, and to automatically include any external scripts linked via <script src=""></script>

Here's a function that (pretty much) does the trick. Although I'm sure it could be cleaned up substantially. It just needs to be included in the function call.

executeScript = function (content) {

handle <script src="foo"> first var src = new RegExp?('<script.*?src=".*?"'); var repl = new RegExp?('<script.*?src="'); var matches = src.exec(content);

var semaphore = 0;

if (matches != null)

{ for (i = 0; i < matches.length; i++)


get the src of the script var scriptSrc = matches[i].replace(repl, ); scriptSrc = scriptSrc.substring(0, scriptSrc.length-1);

this evals remote scripts{

url: scriptSrc, load: function(type, evaldObj) {/* do nothing */ }, error: function(type, error) {alert(type); alert(error); /* do nothing */ }, mimetype: "text/javascript", sync: true




Remove the script tags we matched

repl = new RegExp?('<script.*?src=".*?".*?</script>'); content = content.replace(repl, );

Next, handle inline scripts

Clean up content: remove inline script comments repl = new RegExp?('.*?$', 'gm'); content = content.replace(repl, '


Clean up content: remove carraige returns repl = new RegExp?('[

]', 'g');

content = content.replace(repl, ' ');

Match anything inside <script> tags

src = new RegExp?('<script.*?</script>', 'g');

matches = content.match(src);

For each match that is found... if (matches != null) { for (i = 0; i < matches.length; i++)


Remove begin tag

var repl = new RegExp?('<script.*?>', 'gm'); var script = matches[i].replace(repl, );

Remove end tag

repl = new RegExp?('</script>', 'gm'); script = script.replace(repl, );

Execute commands

setTimeout(script, 250);




Change History (4)

comment:1 Changed 16 years ago by alex

Milestone: 0.3release
Owner: changed from anonymous to alex
Status: newassigned

comment:2 Changed 16 years ago by bill

This is in ContentPane? now (although Josh needs to add a fix to prevent reloading already loaded scripts). Does it need to be in, or some other more general place?

comment:3 Changed 16 years ago by alex

Resolution: wontfix
Status: assignedclosed

I'm not sure it does need to be anywhere but ContentPane?. It doesn't make sense in bind().

comment:4 Changed 15 years ago by (none)

Milestone: 0.3release

Milestone 0.3release deleted

Note: See TracTickets for help on using tickets.