0

I am managing Bookmarklet, that when it clicked create a smiley on any website.
Javascript is perfectly working but I cannot make that same script work perfectly from bookmarklet(annoying output).

javascript jsfiddle
bookmarklet jsfiddle

Now what I do is just arranging for the bookmarklet like

javascript:(function() {
// All javascript code

}
)();

Please suggest how to manage the bookmarklet script so that I can drag and drop the smiley.

vusan
  • 5,221
  • 4
  • 46
  • 81

1 Answers1

0

change

document.onmouseup=new Function("isdrag=false");

to

document.onmouseup = function() {isdrag=false};

Reason: When you wrap all the code in an outer function block to create a bookmarklet, the scope of "var isdrag" is changed from the window level and becomes local to that outer function. On the other hand new Function("isdrag=false") creates a new function at the window level, escaping the current scope, and the "isdrag" in that newly created function can not access the "var isdrag" you think it is accessing. The solution is to create the new function within the same scope as "var isdrag" by not using "new Function(...)".

DG.
  • 3,417
  • 2
  • 23
  • 28