What are the best booklet writing practices

I am writing several bookmarklets for a project that I am currently working on, and I was wondering what is best for writing a bookmarklet. I looked around a bit and this is what I came up with

 javascript:void((function()
  {
    var%20e=document.createElement('script');
    e.setAttribute('type','text/javascript');
    e.setAttribute('src','http://someserver.com/bookmarkletcode.js');
   document.body.appendChild(e)
  })())

I felt this was good because the code can always be changed (from the moment it is requested every time), and yet it acts like a bookmarklet. Are there any problems for this approach? Incompatibility of the browser, etc.? What is the best practice for this?

+5
source share
2 answers

. js , . '?' + new Date() src, , .

+3

script , . (, Gmail) , script , . script , :

var s = document.getElementById('someUniqueId');
if (s) {
  s.parentNode.removeChild(s);
}
s = document.createElement('script');
s.setAttribute('src', 'http://example.com/script.js');
s.setAttribute('type', 'text/javascript');
s.setAttribute('id', 'someUniqueId');
document.body.appendChild(s);

N.B. script, . , . , - script ; , , .

+7

All Articles