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

  • Home
  • SEARCH
  • 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 8204385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:53:06+00:00 2026-06-07T07:53:06+00:00

This is what I have here: manifest.json {…permissions: [ https:/mywebsite.com/],content_scripts: [{ matches : [http://*/*,

  • 0

This is what I have here:

“manifest.json”

{..."permissions": [
"https:/mywebsite.com/"],"content_scripts": [{
  "matches" : ["http://*/*", "https://*/*"],
  "js": ["js/jquery-1.7.2.min.js", "contentScript1.js", "contentScript2.js"],
  "all_frames" : true,
  "run_at": "document_end"
} ]}

“contentScript1.js”

$(document).ready(function() {
$('#someDiv').load('https://mywebsite.com/index.html');}

“contentScript2.js”

function showMessage()
{alert ('Hello World!');}

“index.html”

<a href="" onclick="showMessage();"> <img src="https://mywebsite.com/images/myimage.png"></a>

What I m actually doing here is injecting a clickable picture to the code of the the page that I m visiting and I expect that by clicking the picture a “Hello World” message will be appeared. Despite the fact that the content scripts and the picture are loaded succesfully, when I click on the image the function is not called and I get the following error in the console:

Uncaught ReferenceError: showMessage is not defined

I suppose that it cannot find the function as it is looking for it in the website that I have injected the code and not in the content scripts. But why is that, I mean if I call the function within the content script when it is loaded and not by clicking the image, the message appears. Can anyone get me out of here?

  • 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-07T07:53:07+00:00Added an answer on June 7, 2026 at 7:53 am

    You did not understand my solution to avoid conflicts does not work with your current code. Instead of using $.noConflict, you’re wrapping your script injection function in a $().ready method.

    You have to remove jQuery from the "js" part of the manifest:

      "js": ["contentScript1.js"],
    

    And contentScript1.js

    function injectJs(srcFile) {
        var scr = document.createElement('script');
        scr.src = srcFile;
        document.getElementsByTagName('head')[0].appendChild(scr);
    }
    injectJs(chrome.extension.getURL('js/jquery-min.js'));
    injectJs(chrome.extension.getURL('js/yourscript.js'));
    

    Don’t forget to add js/yourscript.js to web_accessible_resources, so that it can be used:

    "web_accessible_resources": [
        "index3.html",
        "js/jquery-min.js"
        "js/yourscript.js"
    ]
    

    In js/yourscript.js, wrap your function logic in an anonymous function in conjunction with $.noConflict. $.noConflict(true) is used to avoid conflicts with scripts in the page. It restores the original value of $ and jQuery.

    (function(jQuery, $) {
        // Here, you can do anything you want.
        // jQuery and $ refer to the same jQuery object from `js/jquery-min.js`
    
    })(jQuery, jQuery.noConflict(true));
    

    After looking at your question again, I noticed that you’re loading content through ajax: $('#someDiv').load(...). When the script is injected, it runs in the scope of the page. That’s why your AJAX call fails: The request is blocked because of the Same origin policy.

    Now, we can use a different approach to fix your code. Instead of moving the logic from Content script to the page (by an injected script), we modify the page index.html. The click event is not pre-set, but added in the content script. For example:

    “index.html”:

    <a href="" id="showMessage"> <img src="https://mywebsite.com/images/myimage.png"></a>
    

    “contentscript2.js”:

    $('#showMessage').click(showMessage);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JQuery Accordion. I have this page here: http://www.hauppauge.com/site/support/support_colossus.html#tabs-6 What happens is
So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse
I have a manifest.json file that looks like this: { name: Zend Debugger Extension,
I am new to c# and I have this problem: I have here a
I have this code here printf '$request1 = select * from whatever where this
I have this code here, which is intended to allow any type of arguments:
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have this code here: var Person = (function() { var name; var PersonConstructor
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
Newbee question here - I have this method in the view controller m: -(void)

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.