[ACCEPTED]-Loading page and executing JS on it...from JS bookmarklet?-bookmarklet

Accepted answer
Score: 11

The simplest way I found to do this without 10 needing Greasemonkey or something similar 9 is to write your JS so that it checks to 8 see if it is on the appropriate page, and 7 goes there if it isn't. If it is on the 6 page, then it executes the JS/alert/whatever. You 5 have to use the bookmarklet twice, but you 4 just need one bookmarklet, and it may still 3 be quicker/easier the user doing the clicking/whatevering 2 him or herself. So the code would look like 1 this:

if(this.document.location.href != "[url]") { //Are we on the page yet? 
  this.document.location.href = "[url]"; // If not, go there
else {
  if (document.readyState === "complete") { //Wait for the page to finish loading
   // DO STUFF
Score: 4

You want to install the Greasemonkey extension for Firefox. (or 8 gm4ie for IE, or greasemetal for Chrome (PersonalizedWeb also works in 7 a much simpler way for Chrome), greasekit for Safari, or 6 user.js for Opera)

Greasemonkey lets you do exactly 5 this... run a script automatically on every 4 page load (you can choose what pages/sites 3 it loads on)

Otherwise you will need to click 2 your bookmarklet on every page load in order 1 to run your script.

Score: 2

Given there's no better solution, I thought 4 I'd toss out that Opera natively supports 3 user scripts to run on every page load. From 2 there, you could have the script check the 1 current url, and run if on appropriate page.

See here for documentation

Score: 0

Another option is to call window.open(...), and use the 3 window object to manipulate the window. It 2 is also possible to navigate multiple pages 1 this way.

More Related questions