108

Let me first say the problem I have: I need to fill in the same web page a lot of times, and the content that I need to fill in is for the biggest part the same, but is scattered all over the webpage.

The solution i was thinking of: I know there is a way to create some javascript function that you put behind a google bookmark so that when you are on the page, you just click that bookmark, and it will do some things.

I was wondering if anyone used (or created) something like this. If you can make this yourself, how do you start with it? And can you use jquery?

If it's possible to create this, I was also wondering if it would be possible to, when you click, show a pop-up to ask a few parameters, so that I don't need to fill in the same thing 3,4 times

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Brentg
  • 1,509
  • 3
  • 12
  • 13

6 Answers6

168

You can do this using a bookmarklet. A bookmarklet is a bookmark with a URI starting with the pseudo-protocol javascript: followed by URI-encoded JavaScript code. When you trigger the bookmark, browser will run the code in the context of the current page. So you'd go to that page, then use that bookmarklet to fill in your standard information, and there you go.

For example, here's a bookmarklet that, when run, will look for an element with the id someElement on the page and, if found, assign "some value" to its value property:

javascript:(function(){var d=document,e=d.getElementById("someElement");e.value="some value";})();
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • 4
    Yes, that's exactly what I was looking for :) Now that I know the name, I can look up if it allows jquery or not EDIT: it allows jquery (http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/) Is there anyone who knows if it would be possible to make a popup that asks for a certain parameter? – Brentg Sep 18 '13 at 13:00
  • 1
    @Brentg: Yeah, sometimes you just need to know what something is called. You *can* use jQuery in bookmarklets, but it's not generally a good idea, because you can introduce problems with the page. You have to check to see if jQuery is already loaded, load it if not, trigger `noConflict` once it's loaded in case the page uses Prototype or MooTools or something else relying on `$` as a global symbol, and at that point the bookmarklet is getting pretty thoroughly out of hand... :-) – T.J. Crowder Sep 18 '13 at 13:03
  • 3
    @Brentg: Of course, for a bookmarklet that's intended for use on a specific page, if you know the page has jQuery, you're totally free to use it. Your code runs exactly as though it were in a `script` tag on the page, so... – T.J. Crowder Sep 18 '13 at 13:07
  • 2
    @Brentg: *"Is there anyone who knows if it would be possible to make a popup that asks for a certain parameter?"* There's always `prompt`. Or of course, add a `div` to the page with absolute positioning, or even use jQuery UI if the page has it loaded. – T.J. Crowder Sep 18 '13 at 13:08
  • 1
    Yes I can try that, but a pop-up would be a little bit cleaner. I will try to figure it and post results here :) big thanks! – Brentg Sep 18 '13 at 13:34
  • Is it work in Chrome mobile? – Aral Roca Jan 26 '22 at 19:42
  • @AralRoca - I don't know, have you tried it? – T.J. Crowder Jan 27 '22 at 07:32
  • yes, only in Chrome desktop works – Aral Roca Jan 28 '22 at 09:07
  • @AralRoca tried on IOS Chrome, it works. I am on IOS 15.3.1 – Quad Coders Apr 08 '22 at 04:34
24

This bookmarklet creator will come in handy to squish your JavaScript into one line: http://mrcoles.com/bookmarklet/

diazdeteran
  • 1,144
  • 1
  • 13
  • 25
  • 1
    That one choked on my complicated function, but the idea of searching up a generator to build it for you is a good one. – Noumenon Apr 18 '17 at 14:54
11

Here is an example of one that lets you edit the webpage like a document.

javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0
Pang
  • 9,564
  • 146
  • 81
  • 122
Matthias S
  • 205
  • 2
  • 8
4
javascript : { document.getElementById('PlateNo').value='0815';document.getElementById('AppRef').value='013007';document.getElementById('VehicleReg').value='MX53 YMD'; void(0) }
Hari Gillala
  • 11,736
  • 18
  • 70
  • 117
3

You can use prompts and alerts and confirm windows, and I created a game, kind of. It's not that clean though. Here's the javascript-code:

To the editor: there needs to be a "javascript:" at the start for it to work btw

javascript: 
var totalClicks = 0;
for (var i = 0; i < 1000000; i++){
    var message1 = prompt("Clicker Game!\nClicks: "+totalClicks,"remove this text to end the game");
    totalClicks++;
    if (message1 !== "remove this text to end the game"){
        i = Math.Infinity;
    }
}
alert("Thanks for playing my game!\nClicks: "+totalClicks)
0

For Mozilla use like as

javascript:function myFun(){
var d=document;
var e=d.getElementById("someElement");
var e.value="some value";
}myFun();
Umanath
  • 81
  • 6