English 中文(简体)
• 如何在 Chrome推广使用 j门的公开表格上管理习俗
原标题:how to run custom function on an open tab within Chrome Extension using jQuery

我有一个长篇大论,应该操纵目前开放页(表格)的内容。

To take user input I use popup.html with a few input fields. Input from this fields is transmitted to the page (content script) which executes the desired transformation.

The problem is that I cannot run a function which I define in a content script. I tried to define function in a content_script.js itself and tried to insert it into the page via

var new_script2 = document.createElement( script );
code = "function definition goes here";
new_script2.text = code;
document.getElementsByTagName( head )[0].appendChild(new_script2);

无所作为。 加上我,我也看不到 j的物体,即使我按照建议(http://blog.michael-forster.de/2009/08/using-jquery-to-build-google-chrome.html)“rel=“nofollow” 。

在活动之后如何在 Chrome延伸部分开一个公开的禁忌上运行习俗?

[序言]

Below is what I have now and I solved my problem, the key is to be careful with message passing and functions initialization.

My manifest looks as follows

{
  "background_page": "background.html",
  "name": "some",
  "version": "0.1",
  "description": "some",
  "browser_action": {
    "default_icon": "icon.png",
    "default_title": "some",
    "popup": "popup.html"
  },
   "content_scripts": [ {
      "js": [ "javascripts/jquery-1.5.min.js", "javascripts/jquerylatest.js", "javascripts/content_script.js" ],
      "matches": [ "http://*/*", "https://*/*", "file://*/*" ],
      "run_at": "document_end"
   } ],
   "permissions": [ "tabs", "http://*/", "https://*/" ]
}

In popup.html 我创建了一个县,并指派了一个活动手向背景页发送信息。 html

    $( "#create-user" )
        .button()
        .click(function() {
            //~ alert(allFields.val());
            //~ var annot = [attrValue, attrType];
            chrome.tabs.getSelected(null, function(tab) {               
            chrome.tabs.sendRequest(tab.id, {"attrValue" : attrValue.val(), "attrType" : attrType.val()}, 
            function readResponse() { console.log("got response in popup");} );
            window.close();
            });
        });

在背景资料中,我听了一名群众发出的信息。

var tab_id = -1;

chrome.tabs.getSelected(null, function(tab) {
        tab_id = tab.id;
    });

chrome.extension.onRequest.addListener(function(request, sender) {
    console.log("in bg.js addlistener method " + request);
        chrome.tabs.executeScript(tab_id, {file:"javascripts/content_script.js"});
    });

and redirects them further to the content script to use for page modification. content_script listens as follows:

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
//do your manipulation here
});

最后,不要忘记,将jquery图书馆纳入贵展期的javascripts/小册。

问题回答

根据我的理解,除对某项活动(如<条码>关键或<条码><<<>>>)重新附后外,投放的 Java字功能不能节省。 (如果我错!)

相反,我建议使用chrome.tabs.execute texts(tabId, details)>,并在以下代码内撰写:tdetails.code,或使该代码通过<条形形码.js文档中添加。

But again, injected functions will be removed once the script is finished.
So put your function and other code in a content script, inject it, and your content script can use its function(s) until the script finishes.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签