[code] Cleanup After execute_script

[code] Cleanup After execute_script

Postby Jim » Tue May 29, 2012 1:56 pm

This code cleans-up the cruft left behind when using execute_script. (reference thread)

Chris' version: (viewtopic.php?p=274499#p274499)

Code: Select all
function corePurge(){
   coll = document.body.childNodes;
   for(a=0; a < coll.length; a += 1){
      if (coll[a].tagName ===   "SCRIPT" && coll[a].id === ""){
         document.body.removeChild(coll[a]);
                        a -= 1;
      }
   }   
}


My version:

Code: Select all
function purge_script_tags() {
  var b = document.body;
  var last_node = b.lastChild;
  while(last_node.nodeName === "SCRIPT") {
     b.removeChild(last_node);
     last_node = b.lastChild;
  }
}
0
Hi

Jim 
Global Moderator
 

Re: [code] Cleanup After execute_script

Postby thomthom » Tue May 29, 2012 1:59 pm

jQuery version:
$('body script').detach();
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] Cleanup After execute_script

Postby chrisglasier » Wed May 30, 2012 12:49 am

Jim wrote:...

My version:

Code: Select all
function purge_script_tags() {
  var b = document.body;
  var last_node = b.lastChild;
  while(last_node.nodeName === "SCRIPT") {
     b.removeChild(last_node);
     last_node = b.lastChild;
  }
}


This would remove all last scripts including ones not by execute_script - UHMS
0
With JSON machines we can analyse what is to be achieved so that IT can help with automation to achieve it.
User avatar
chrisglasier 
PluginStore Author
PluginStore Author
 

Re: [code] Cleanup After execute_script

Postby Dan Rathbun » Wed May 30, 2012 2:20 am

And in Chris' edition.. if a developer wanted to avoid being cleaned up, he need only set an id attribute on the script object.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: No registered users and 15 guests

    Visit our sponsors: