Search code examples
javascriptbookmarklet

Bookmarklet i'm making is somehow performing document.write though its not in the code


I am trying to write a bookmarklet that toggles the ability to make any text on the page editable, but when I execute it, it seems to be performing something along the lines of document.write('off'). Here's the code/bookmarklet:

javascript: if (document.body.contentEditable == "true") {
  document.body.contentEditable = "true";
  document.designMode = 'on';
} else {
  document.body.contentEditable = "false";
  document.designMode = "off"
}

Solution

  • try an IIFE

    javascript:(function(){if (document.body.contentEditable == "true") {
      document.body.contentEditable = "true";
      document.designMode = 'on';
    } else {
      document.body.contentEditable = "false";
      document.designMode = "off"
    }})()