Implement javascript file with least number of characters?

I am working on a bookmarklet and thought I would challenge: how to insert as few javascript files as possible from a link as few characters as possible.

Here is the shortest thing I could come up with:

javascript:(function(d){d.body.appendChild(d.createElement('script')).src='URL'})(document)

These are 88 characters without a URL.

Is it possible that a stack overflow javascript guru is better? I will accept a working answer with the least number of characters, so put on your thought caps!

(One thing: the bookmarklet should work in all major browsers. This is a smart solution, but it does not work in all major browsers because it returns a value.)

+3
source share
3

, String.prototype , .

javascript:with(document)(body.appendChild(createElement('script')).src='URL')._
+1
javascript:void(with(document)body.appendChild(createElement('script')).src='URL')

79 . Ben Blank void.

+6

I'm not sure why you wrap this in the function window - it seems that it works fine without it and is almost a dozen characters shorter:

javascript:void(document.body.appendChild(document.createElement('script')).src='URL')

Also, your implementation looks pretty minimalist.

+5
source

Source: https://habr.com/ru/post/1708126/


All Articles