Opening google search results simultaneously in new tabs in Chrome

JavaScript, often abbreviated as JS, is a high-level, interpreted programming language that conforms to the ECMAScript specification.
jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation.

We can use them to do a wide range of things which we do manually and is tiresome.


Note: On first run of the script a popup will come. We have to allow popups because Chrome wants to know if we want multiple tabs to be used or not. Then re-run the script.

allow popups

How to run:
Search for anything on Google. On Google search results page paste the script on the developer tools console window and press Enter and see the magic.

Let’s see the code:





// dynamically loading the jQuery library
javascript: var fileref = document.createElement('script');
fileref.setAttribute("type", "text/javascript");
var arr = []; //this array will contain the links of google search results.
setTimeout(function() {  
// We are using setTimeout function so that                       
// jQuery library is loaded fully before running 
//rest part of the code
   // Accessing the DOM and using it to extract
   // links from the search results
    var count1 = $("div.bkWMgd").length;
    var j;
    // There are many div's with this class "div.bkWMgd" but we 
    // will be using only the div's which will be 
    // containing the search results links, 
    // so we have to filter out the div's by performing if-else.
    for (j = 0; j < count1; j++) {
        if ($("div.bkWMgd")[j].firstChild == null) { 
    // not using this section because it does not contain the links
        } else if 
      ($("div.bkWMgd")[j].firstChild.className.toString().trim() === "srg") {
            // This div contains the serach result links
            var count2 = $("div.bkWMgd")[j].firstChild.children.length;
            var i;
            for (i = 0; i < count2; i++) {
          // inserting search results links into the array
            count2 = 0;
        } else if 
     ($("div.bkWMgd")[j].firstChild.innerHTML.toString().trim()==="Web results") {
        // This div also contains the search result links
            var count2 = $("div.bkWMgd")[j].firstChild.children.length;
            try {      // Handling error if encountered using try catch block
                var i;
                for (i = 0; i < count2; i++) {
                } // inserting links into the array
                count2 = 0;
            } catch (err) {
                console.log('Error handled in: ', j + 'loop');
}, 1000);
// opening multiple tabs with the links in the array
function open_win() {
    for (var i = 0; i < arr.length; i++) {
// in 2.5 seconds multiple tabs will get 
// open with the search results links
setTimeout(function() {
}, 2500);  


Live results
Search results opened in mutiple tabs

My Personal Notes arrow_drop_up

Competitive Programmer, Full Stack Developer, Technical Content Writer, Machine Learner

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.