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.
Examples:
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.

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"); fileref.setAttribute("src", document.body.appendChild(fileref); 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 continue; } 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++) { arr.push( $("div.bkWMgd")[j].firstChild.children[i].children[0]. firstChild.firstChild.firstChild.href.toString().trim()); // inserting search results links into the array } count2 = 0; continue; } else if ($("div.bkWMgd")[j].firstChild.innerHTML.toString().trim()==="Web results") { // This div also contains the search result links $("div.bkWMgd")[j].firstChild.remove(); 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++) { arr.push( $("div.bkWMgd")[j].firstChild.children[i].children[0]. firstChild.firstChild.firstChild.href.toString().trim()); } // 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++) { console.log(arr[i]); window.open(arr[i]); } } // in 2.5 seconds multiple tabs will get // open with the search results links setTimeout(function() { open_win(); }, 2500); |
Live results

Recommended Posts:
- Text to Voice conversion using Web Speech API of Google Chrome
- How to disable tabs in Bootstrap ?
- Binary Search in PHP
- PHP multidimensional array search by value
- How to search by key=>value in a multidimensional array in PHP ?
- Search Bar using HTML, CSS and JavaScript
- How to search by multiple key => value in PHP array ?
- HTML | <input type="search">
- HTML | DOM Anchor search Property
- HTML | DOM Input Search Object
- Search Engine Optimization (SEO) | Basics
- HTML | DOM Input Search value Property
- HTML | DOM Location Search Property
- Elasticsearch Search Engine | An introduction
- Case insensitive search in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.



