3

I'm looking to combine these 2 bookmarklets into 1 bookmarklet that toggles the designMode on and off:

On: javascript:document.body.contentEditable='true';%20document.designMode='on';%20void%200

Off: javascript:document.body.contentEditable='false';%20document.designMode='off';%20void%200

I had tried some if else statements but can't seem to detect if designMode was on or not. So not sure what I was doing wrong. Any help would be appreciated.

srbrussell
  • 151
  • 2
  • 8

2 Answers2

7

SOLVED (i had typos, oops) :

javascript:(

function () {
    if (document.documentElement.contentEditable === false || document.designMode === "off") {
        document.body.contentEditable='true';
        document.designMode='on';
        void 0;
    } else if (document.documentElement.contentEditable === true || document.designMode === "on") {
        document.body.contentEditable='false';
        document.designMode='off';
        void 0;
    }
})();
srbrussell
  • 151
  • 2
  • 8
  • 4
    The one liner is: `javascript:(function () {if (document.documentElement.contentEditable === false || document.designMode === "off") {document.body.contentEditable='true';document.designMode='on';void 0;} else if (document.documentElement.contentEditable === true || document.designMode === "on") {document.body.contentEditable='false';document.designMode='off';void 0;}})();` – Matt Sephton Feb 13 '13 at 18:18
  • p.s. All browsers support bookmarklets with multi-lines. – ViliusL Nov 26 '20 at 10:36
  • 1
    FWIW, 10 years later, here's a more compact version: `javascript:((d,ce,dm)=>(d.body[ce]==true||d[dm]=="on"?(d.body[ce]="false",d[dm]="off"):(d.body[ce]="true",d[dm]="on"))&&void 0)(document,"contentEditable","designMode")` – jdunning Oct 18 '22 at 00:11
-3

This works on Google Chrome

   data:text/html, <html contenteditable>