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

javascript - How to open url as "chrome-extension" in web page? - Stack Overflow

programmeradmin0浏览0评论

I have one web page and one chrome extension, how can I open url like this chrome-extension://chrome-id/page.html. Here is my code:

 $(document).on('click', '#btnOpenChromeExtension', function () {
    window.open("chrome-extension://chrome-id/webpage.html", "_blank");
 });

But when click, it open new tab in blank page with url is: about:blank. How can I open link is chrome-extension ?

I have one web page and one chrome extension, how can I open url like this chrome-extension://chrome-id/page.html. Here is my code:

 $(document).on('click', '#btnOpenChromeExtension', function () {
    window.open("chrome-extension://chrome-id/webpage.html", "_blank");
 });

But when click, it open new tab in blank page with url is: about:blank. How can I open link is chrome-extension ?

Share Improve this question asked May 6, 2015 at 8:00 dev.knockoutdev.knockout 3992 gold badges5 silver badges12 bronze badges 2
  • Does it work (or do something else) when you leave out the second parameter? From w3schools: _blank - URL is loaded into a new window. This is default so there's no need to specify it. Still a strange situation... Does the URL you supply lead to the extension when you paste it into the address bar manually? – Nils O Commented May 6, 2015 at 8:17
  • @NilsO It work normaly with url contains "http", but it seem to be not work with url contains "chrome-extension" – dev.knockout Commented May 6, 2015 at 8:20
Add a ment  | 

2 Answers 2

Reset to default 7

This is restricted due to the extension policies. You need to add to the extension's manifest.json file the following:

{
    ...
    "web_accessible_resources": [
        "page/mypage.html"
    ],
    ...
}

Of course, this must be your extension. This is the only way I know to make it work.

Try this:

$(document).on('click', '#btnOpenChromeExtension', function () {
      window.location.href = "chrome-extension://chrome-id/webpage.html";
      //        OR       
      window.location.replace("chrome-extension://chrome-id/webpage.html");
});
发布评论

评论列表(0)

  1. 暂无评论