最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open chrome options from popup - Stack Overflow

programmeradmin7浏览0评论

When I run my code, it es up with "about blank" instead of my extension options. I would like it to open the options in front of the extensions. Here is some of my extension code-

popup.js:

document.getElementById('div_options').onclick = openOps;
function openOps() {
       window.open("chrome://extensions/?options=pgapbgeppkbeghldobmjehpbdleapdip");
       closeAndReloadPopup();
    };

popup.html:

<li>
    <a href="#"><div id="div_options">Options</div></a>
</li>

manifest.json:

{   
"background": {
        "page": "background.html"
    },
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"page_action": {
          "default_icon": {
            "19": "images/icon19.png",
            "38": "images/icon38.png"
          },
          "default_title": "Scratch theme loader",
          "default_popup": "popup.html"
        },
"options_ui": {
            "page": "options.html",
            "chrome_style": true
        },
"web_accessible_resources": ["src/options/options.html"],
    "permissions": [
        "tabs",
        "storage",
        "declarativeContent",
        "/*",
        "/*"
    ]
}

options.html:

<html>
    <stuff>
</html>

When I run my code, it es up with "about blank" instead of my extension options. I would like it to open the options in front of the extensions. Here is some of my extension code-

popup.js:

document.getElementById('div_options').onclick = openOps;
function openOps() {
       window.open("chrome://extensions/?options=pgapbgeppkbeghldobmjehpbdleapdip");
       closeAndReloadPopup();
    };

popup.html:

<li>
    <a href="#"><div id="div_options">Options</div></a>
</li>

manifest.json:

{   
"background": {
        "page": "background.html"
    },
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"page_action": {
          "default_icon": {
            "19": "images/icon19.png",
            "38": "images/icon38.png"
          },
          "default_title": "Scratch theme loader",
          "default_popup": "popup.html"
        },
"options_ui": {
            "page": "options.html",
            "chrome_style": true
        },
"web_accessible_resources": ["src/options/options.html"],
    "permissions": [
        "tabs",
        "storage",
        "declarativeContent",
        "https://scratch.mit.edu/*",
        "https://pastebin./raw/*"
    ]
}

options.html:

<html>
    <stuff>
</html>
Share Improve this question asked Apr 16, 2016 at 19:40 MelkorMelkor 7991 gold badge12 silver badges30 bronze badges 1
  • In general, don't use window.open in extensions. Rely on chrome.tabs and chrome.windows, creation does not require permissions. – Xan Commented Apr 16, 2016 at 20:40
Add a ment  | 

1 Answer 1

Reset to default 12

Use the remended way: chrome.runtime.openOptionsPage(callback)

Open your Extension's options page, if possible. The precise behavior may depend on your manifest's options_ui or options_page key, or what Chrome happens to support at the time. For example, the page may be opened in a new tab, within chrome://extensions, within an App, or it may just focus an open options page. It will never cause the caller page to reload. If your Extension does not declare an options page, or Chrome failed to create one for some other reason, the callback will set lastError.

https://developer.chrome./extensions/runtime#method-openOptionsPage

Alternatively, chrome.tabs.create({ url: "chrome://extensions/?options=" + chrome.runtime.id }, callback) or chrome.tabs.create({ url: "options.html" }, callback)

发布评论

评论列表(0)

  1. 暂无评论