Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:54:37+00:00 2026-06-15T05:54:37+00:00

I am a newbie in writing Google Chrome Extensions. I (specifically) intended to make

  • 0

I am a newbie in writing Google Chrome Extensions. I (specifically) intended to make a browser action extension which when clicked would open all the links(URLs) on a page resulting when we Google Search any topic.
Till now I’m able to make something which highlights and alerts(javascript alert function ) the links present on any webpage.
The manifest.json and the script file required are given below:-

manifest.json==>

{
"name": "Highlight then alert.",
"description": "Highlight and alert links on a webpage.",
"version": "1.1",
"background": {
"scripts": ["write.js"]
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "highlighter",
"default_icon": "highlight_16x16.png"
},
"manifest_version": 2
}

write.js==>

chrome.browserAction.onClicked.addListener(function(tab) {

var action_url1 = "javascript:(function()
{for(i=0;i<document.links.length;i++)alert(document.links[i]);})();";

var action_url2 = "javascript:(function()
{for(i=0;i<document.links.length;i++)document.links[i].style.backgroundColor='#F00';})();";

chrome.tabs.update(tab.id, {url: action_url1});
chrome.tabs.update(tab.id, {url: action_url2});
});

Right now, I am writing a simple inline javascript code , storing them in different variables as shown and then passing them into the Chrome Object method
– chrome.tabs.update() to perform the the highlight and alert operation.
I need to figure out a way to perform the same operation by writing an absolute javascript function rather than passing through a variables.
Suggestions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:54:38+00:00Added an answer on June 15, 2026 at 5:54 am

    Little bit unsure exactly what you want, but my guess is you want a way of injecting the code your testing on a Browser Action click without that bookmarklet style your doing right now.
    If so, this is how I do it…
    manifest.json

    {
      "name": "Testing from a PopUp",
      "version": "1.0",
      "permissions": [
        "tabs", "<all_urls>"
      ],
      "browser_action": {
          "default_title": "Inject Test Script",
          "default_icon": "icon.png",
          "default_popup": "popup.html"
      },
      "manifest_version":2
    }
    

    popup.html

    <!doctype html>
    <html>
      <head>
        <script src="popup.js"></script>
      </head>
      <body>
      </body>
    </html>
    

    popup.js

    chrome.tabs.executeScript(null,{file:"injectedCode.js"});
    window.close();
    

    injectedCode.js

    log = function() {
        for(i = 0; i < document.links.length; i++) console.debug(document.links[i]);
    }
    
    highlight = function() {
        var links = document.querySelectorAll('div[id="search"] ol li h3 a');
        for(var i = 0,length=links.length>10 ? 10 : links.length; i < length; i++) links[i].style.backgroundColor = '#F00';
    }
    
    log();
    highlight();
    

    The bit you should look up is executeScript
    http://developer.chrome.com/extensions/tabs.html#method-executeScript
    Personally I like this way for testing little bits before turning them into content scripts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[I'm a YUI newbie] I'm writing a Chrome extension that needs to change the
NewBie Androider here. I am writing a code in which user enters only one
I am making a extension for Google Chrome where i have to store JSON
Newbie to C. I'm writing an ANSI C program (on Linux using gcc 4.4.6)
I'm a newbie with a little experience writing in BASIC, Python and, of all
I am newbie at using DataSet. I am writing a program with VB.NET, there
I am writing a website using C# razor code. I'm a total newbie when
I am a newbie to Android development. I am writing an app for my
As a newbie to Python, and mainly having a background of writing scripts for
I am newbie in writing SQL queries and this is for a mySQL database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.