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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:17:12+00:00 2026-06-03T13:17:12+00:00

I want to detect the button event in the page,I inject my script.js strong

  • 0

I want to detect the button event in the page,I inject my script.js strong text file from background.html, when button is click,I want to alert some message than let button do his work.
so I have two question,

1.I try to use jquery in my srcript.js but its seem not work,i have include jquery file in background.html, how can i use jquery in .js file?

2.how to detect button event when it be click?

below is my code:

background.html

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

<script>
  chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript(null,{file:'script.js',allFrames:true});
  });
</script>

script.js

if( self.frameElement && self.frameElement.tagName == "IFRAME" ){
  $(":button").bind("click",function(){
    alert("iframe button");
  });
}
else{
  $(":button").bind("click",function(){
    alert("parent button");
  });
}
  • 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-03T13:17:14+00:00Added an answer on June 3, 2026 at 1:17 pm

    As to why jQuery in your script is not working, that is because you have included jQuery in your background page, you need to load it into the user’s page’s extension’s world. To make it clear. Your script.js is supposed to be loaded in user’s page. Chrome will load into the page but in an isolated world which is your extension’s world on that page. You have to load jQuery on that page just like your script.js. As below:

    <script>
        chrome.browserAction.onClicked.addListener(function(tab) {
            chrome.tabs.executeScript(null,{file:'jQuery.js',allFrames:true});
            chrome.tabs.executeScript(null,{file:'script.js',allFrames:true});
        });
    </script>
    

    As to your other question regarding listening to button clicks, its unclear from your question which button are you speaking of. Is it the browser action button? If that is the case your code will work just fine. If it is a button on user’s DOM, you will have to add script as described above that listens to the click event and informs your extension (background.html), your background page in turn will load the script.

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

Sidebar

Related Questions

i see there is this syntax for detecting any button click <script type=text/javascript> $(document).ready(function()
I have a webform and i want to detect if F5 button was pressed
I want Detect the largest number in inputs and done alert for it, How
I want to detect and replace tab characters in a bit of HTML like
I want to be able to detect the phone lock event. When my app
I have this right now: $(document).click(function(e) { alert('clicked'); }); In Firefox, this event is
I would like to detect mouse events like left button click, right button click
I am facing a problem in the jquery click event. My web page involves
I have a button click event handler which says this.Close() In the FormClosing event
I want to be able to detect a single click or a double click

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.