Question

I tried for months to build this myself before asking but at this stage I'm forced to accept that I will only ever be the worst kind of code-stealing script-kiddie and am terrible at javascript.

Confession over, I need a single bookmarklet that when run, will get 1 variable from the URL (i.e. q=2075083, ALWAYS a 7 digit number, q will always be the id), open 2 new tabs, each one using the variable grabbed to perform a custom search in each of the other two tabs.

There's only one more caveat - I will need to add more search tabs in the future :/

And I'm LOST trying to make it myself. Can anyone lend their expertise or advice?

This is an operation I perform hundreds of times a day, and it would significantly reduce the amount of mouse clicks and copy-paste operations I'll do.

Thank you dearly to anyone who can help or advise.

P.S. I've gotten as far as the code below (which I'll make in to a bookmarklet at a later stage).

function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

Calling getQueryVariable("q") returns the number I need, but I've no idea how to put it to use creating the two other tabs searching for it.

Was it helpful?

Solution

javascript:var q=document.location.href.match(/q=(.*?)(?=&|$)/i);if(!q)alert('q not found');else {q=q[1];window.open('http://google.com/search?q='+q);window.open('http://bing.com/search?q='+q)}

Replace google.com and bing.com with your choices.

Add another window.open(...) for additional tabs.

(Since you are new to this site, don't forget to click the green checkbox to accept an answer.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top