Results 1 to 2 of 2

Thread: loadScripts using eval instead of appending to dom

  1. #1
    Ext User
    Join Date
    Mar 2007
    Vote Rating

    Default loadScripts using eval instead of appending to dom

    Ok, I don't want to get into the debate as to whether or not using eval is the correct thing to do. I did this more as an exercise to help me understand javascript better. This patch replaces the portion of element.update that appends inline javascript in the string supplied to the head element of the document, with an eval statement that runs on the string. References to javascript source files should still be appended to the head of the document, though I haven't tested it.

    I've tested this in ie6 firefox

    To use this, you would just run this javascript after you load the yui-ext.js file.

    YAHOO.ext.Element.prototype.update = function(html, loadScripts){
            this.dom.innerHTML = html;
            if(!loadScripts) return this;
            var dom = this.dom;
            var _parseScripts = function(){
                var s = dom.getElementsByTagName("script");
                var docHead = document.getElementsByTagName("head")[0];
                //   For browsers which discard scripts when inserting innerHTML, extract the scripts using a RegExp
                if(s.length == 0){
                    var re = /(?:<script.*(?:src=[\"\'](.*)[\"\']).*>.*<\/script>)|(?:<script.*>([\S\s]*?)<\/script>)/ig; // assumes HTML well formed and then loop through it.
                    var match;
                    while(match = re.exec(html)){
                         var s0 = document.createElement("script");
                         if (match[1])
                            s0.src = match[1];
                         else if (match[2])
                } else {
                  for(var i = 0; i < s.length; i++){
                     var s0 = document.createElement("script");
                     s0.type = s[i].type;
                     if (s[i].text) {
                     } else {
                        s0.src = s[i].src;
            // set timeout to give DOM opportunity to catch up
            setTimeout(_parseScripts, 10);
            return this;

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    New York, NY
    Vote Rating


    Joe, this is similar to what I am doing in the latest code, although there is no more inserting into the html body and fetching the tags. The reason is because IE7 discards some scripts and not others.

Similar Threads

  1. Element.update() and loadScripts...
    By Animal in forum Ext 1.x: Bugs
    Replies: 11
    Last Post: 20 Apr 2007, 3:38 PM
  2. appending an event listener
    By hicker in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 23 Feb 2007, 10:41 PM
  3. understanding loadScripts
    By jbowman in forum Community Discussion
    Replies: 1
    Last Post: 17 Nov 2006, 9:20 AM
  4. eval-ing json
    By christocracy in forum Community Discussion
    Replies: 6
    Last Post: 19 Oct 2006, 6:45 AM

Posting Permissions

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