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 8668143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:08:28+00:00 2026-06-12T18:08:28+00:00

I have a simple Chrome extension that opens new Chrome tabs on clicking some

  • 0

I have a simple Chrome extension that opens new Chrome tabs on clicking some URLs.
I was using with success a simple in-line javascript

...
<script type="text/javascript">
function LaunchURL(oURL) {
var launchType = localStorage["LS_LaunchType"];           
    switch (launchType) {
        case "TN":
            chrome.tabs.create({ url: oURL });
            break;
        case "WN":
            chrome.windows.create({ url: oURL });
            break;
        default:
            chrome.tabs.create({ url: oURL });
            break;
    }
}
</script>   
...
<a href="javascript:LaunchURL('http://foo.com')">My hyperlink</a>

I want to upgrade manifest.json to version 2, but now the in-line script are blocked for security reasons.
How can I open new tabs?
I have tried to create a separate javascript file with the previous function, but without success.

  • 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-12T18:08:29+00:00Added an answer on June 12, 2026 at 6:08 pm

    What you have should work correctly in an external javascript file, but you will need remove the script from the anchor tag. Instead just have the url in the anchor tag and add an event listener in the javascript that prevents the default action.

    So in the page you have:

    <script src="external.js"></script>
    <a href="http://foo.com">My hyperlink</a>
    

    And in external.js you have:

    document.addEventListener("DOMContentLoaded", function() {
    
        var anchors = document.querySelectorAll("a");
        for (var i = 0; i < anchors.length; i++) {
            anchors[i].addEventListener("click", function(event) {
               LaunchURL(event.currentTarget.href);
               event.preventDefault();
            });
        }
    
        function LaunchURL(oURL) {
            var launchType = localStorage["LS_LaunchType"];           
                switch (launchType) {
                    case "TN":
                        chrome.tabs.create({ url: oURL });
                        break;
                    case "WN":
                        chrome.windows.create({ url: oURL });
                        break;
                    default:
                        chrome.tabs.create({ url: oURL });
                        break;
                }
            }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple Google chrome extension that overrides CSS classes using the
I am building my first chrome extension, for that I want to have some
I have a simple Chrome extension that uses the content script feature to modify
I have a simple function that works in chrome, but in Internet explorer (9)
I have added functionality to my Chrome extension such that the icon button changes
I am experiencing some problems with a google chrome extension I have made. I've
I want to develop a simple Chrome extension in C++, using NPAPI, which does
I'm using simple custom type in content script of chrome extension. Array of items
I have a Google Chrome extension that creates a select-all function for a search
I'm writing an extension that opens a tab when Chrome first runs, technically means

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.