Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining two bookmarklets

Yesterday I discovered Bookmarklets and am totally in love. I wrote several to reduce the number of clicks for a few common tasks on my favorite websites. What I would like to do now, if possible, is to combine the actions of two of these bookmarklets into one single script/link. The current set up is as follows: Bookmarklet 1 (B1) performs an action (on URL 1) that loads a page (URL 2) where Bookmarklet 2 (B2) then enters a standard set of data into a form and submits it.

I have tried all sorts of variations of the following:

javascript:(function(){w=window.open(codeFromB1,'CatchyPageTitle'); w.TryToWriteSomethingToTheTheNewWindowToPassAndCallFunctionB2;)}();

But all of my attempts at w.TryToWriteSomethingToTheTheWindow yield errors of varying types. My most recent attempt was to use something like:

alert(w.document.getElementsByTagName("form").length); which gives the count from the calling page on the first time called, but the count from the new window on the second time called...

So anyway, that's my story for today.

In summary, I'm a lost soul in need of guidance. I have two script actions that take place on two different pages that I would like to combine into one code snippet that can be saved as a Bookmarklet. I need someone to point me in the right direction so that I can figure out how to 'link' the two pages/scripts so as to create one spectacular Bookmarklet.

Thanks in advance for any help.


Also, I have a mock data Array() that I am using to finish the rest of the script and found one more question for those more intelligent than am I. Part of B2 reads:

wdoc.forms[0].t5.value=#;

where t5 is the name of the input/text in the form. Why does that work but:

thisInput = 't'.concat(i); // where i=5 in the for-loop wdoc.forms[0].thisInput.value=#;

gives me an error - "thisInput" is undefined. I also tried creating an array with the input/text names like:

document.forms[0].thisInput[i].value=#;

but that gives the same error. Any suggestions?

like image 571
Aaron Luman Avatar asked Sep 17 '26 21:09

Aaron Luman


1 Answers

Is URL 1 on a different domain (or subdomain) to URL 2? If so, you will be coming up against a cross-domain issue. You could resolve it using HTML5 cross-window messaging, at least for the browsers that support it.

You might also be interested in Greasemonkey if you're willing to be Firefox-specific and require anyone using it to have the Greasemonkey extension installed. I've used it to easily write multi-page bookmarklets which go through complicated forms, or collect data from multiple search pages. At the start of the script, you simply choose what to do next based on document.location.href. You can also exploit the window.name hack to share information between pages.

like image 184
mahemoff Avatar answered Sep 19 '26 10:09

mahemoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!