Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your clickable bookmarklet got broken and you want it back, you can create a <strong>clickable button</strong> instead using <a href="https://addons.mozilla.org/en-US/firefox/addon/custom-buttons/" rel="nofollow">Custom Buttons</a> Firefox extension.</p> <p>The advantages of button over running from Scratchpad:</p> <ul> <li>you can actually <strong>save</strong> the bookmarklet (button),</li> <li>you can have a <strong>nice own icon</strong> (create some image e.g. PNG file, import it and base64_encode it inside the new button dialog).</li> </ul> <p>The extension is a bit special because <strong>the buttons run at Firefox chrome level</strong>, so they're a bit more privileged (you can interact with the browser's API), and there's no 1-to-1 correspondence between normal JS and the button code (<strong>it needs some tweaking</strong>). More precisely, <code>document</code> and <code>window</code> seen from button are not the ones you were expecting.</p> <p>However, you can assign the 'good' <code>window</code> and <code>document</code> to your variables, and then work on these variables instead (better not redefine window;)</p> <p>Here's a sample code I written which works pretty well in Fx10:</p> <pre class="lang-js prettyprint-override"><code>// get proper 'window' and 'document' into our private variables var theWindow = window.top.getBrowser().selectedBrowser.contentWindow; var theDocument = theWindow.document; // here we go var input = theDocument.getElementById("foo"); input.focus(); // just to show you it's working, unnecessary in fact // simulate keyboard event var evt = theDocument.createEvent("KeyboardEvent"); evt.initKeyEvent ("keypress", true, true, theWindow , 0, 0, 0, 0, 0, 65); // 65 == "A" input.dispatchEvent(evt); // show alert after 2 sec theWindow.setTimeout( function(){ input.value += "B"; theWindow.alert(input.value); // alerts "AB" },2000); </code></pre> <p>Instead of using global functions directly (like <code>setTimeout</code>, or <code>alert</code>), you have to put <code>theWindow.</code> before them, and replace <code>document</code>/<code>window</code> with local <code>theDocument</code>/<code>theWindow</code> and it's seems to be working. I haven't tested it thoroughly however with very complicated cases.</p> <p><strong>To add a button,</strong> right click on any button you already have and choose 'Add new button...'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload