English 中文(简体)
我如何更新/重载 Chrome延?
原标题:How do I refresh/reload a Chrome Extension?

I m developing an extension in Chrome 4 (currently 4.0.249.0) that will show the user s StackOverflow/SuperUser/ServerFault reputation in the status bar. I ve designed an options page to get the user s profile IDs and I save them to localStorage and read them well in the extension. It all works great.
The problem is I cannot find a (programmatic) way to refresh the extension upon options saving. I tried calling location.reload(); from the extension page itself upon right clicking it - to no avail. I pursued it further and tried looking at what Chrome s chrome://extensions/ page does to reload an extension, and found this code:

/**
 * Handles a  reload  button getting clicked.
 */
function handleReloadExtension(node) {
  // Tell the C++ ExtensionDOMHandler to reload the extension.
  chrome.send( reload , [node.extensionId]);
}

我将这部法典复制给我的活动的手稿并不有用(而且是,我尝试用实际代码取代<代码>。 请允许我协助我以正确的方式这样做,或向我指出,这种延长是正确的? 一旦完成,我就把延期及其来源放在我的博客上。

最佳回答

您的延伸javascript代码不便于使用,如新的表格页、历史和扩展页等,因此无法与C++控制器代码联系。

您可向安装的用户推广最新信息,见http://code.google.com/chrome/extensions/autoupdate.html>rel=“noreferer”>。 用户申请将更新,一旦电离层发生故障或重新启用浏览器。 然而,你无法按方案重载用户的推广。 我认为,这将是一种安全风险。

问题回答

Now the simplest way to make extension to reload itself is to call chrome.runtime.reload(). This feature doesn t need any permissions in manifest. To reload another extension use chrome.management.setEnabled(). It requires "permissions": [ "management" ] in manifest.

窗户:地点:重荷为我工作

我使用的是ium6.x,这样可以固定在新的版本中。

我在an分机上也存在同样的问题。

在<代码>后继场.js内,可在https://developer.chrome.com/extensions/storage#event-onChanged” rel=“nofollow”>>chrome.storage.onChanged内查阅储存变化情况,并符合复读逻辑。

例如:

// Perform a reload any time the user clicks "Save"
chrome.storage.onChanged.addListener(function(changes, namespace) {
  chrome.storage.sync.get({
    profileId: 0
  }, function(items) {

    // Update status bar text here

  });
});

您也可通过将<条码>改动/条码>参数考虑在内,重载您的延伸部分<>。 <代码>chrome.runtime.reload(>)可能比较容易,但间接费用较少。





相关问题
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.

热门标签