javascript - Google Chrome 扩展程序打开网址

标签 javascript html google-chrome google-chrome-extension

所以我对制作扩展有点陌生,所以我想从一个简单的开始。好吧,我认为这并不太难,但我无法让我的扩展程序以隐身模式和正常模式打开新标签页。

弹出页面:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
    <link href='style.css' rel='stylesheet' type='text/css'> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript">
    function Tabs() {
    chrome.browserAction.onClicked.addListener(function() {
    chrome.tabs.create({'url': "http://www.google.com"});
    });
    }
    </script>
    <base target="_blank">
</head>
<body> 
        <div id="Google">
        <a href="google.nl"><input type="submit" onClick="Tabs" class="btn search-submit" value="Google"> </a>
        </div>
        <div id="Google">
        <form action="websitelink" method="get" target="_blank">  
        <input type="submit" class="btn search-submit" value="website1"> 
        </form>
        </div>
        <div id="Twitter">
        <form action="websitelink" method="get"target="_blank">  
        <input type="submit" class="btn search-submit" value="website2"> 
        </form>
        </div>
        <div id="Youtube">
        <form action="websitelink" method="get"target="_blank">  
        <input type="submit" class="btn search-submit" value="website3"> 
        </form>
        </div>
</body>
</html>

我的 list 文件:

{
  "name": "My Helper",
  "version": "1.0",
  "description": "My Helper",
  "manifest_version": 2,
  "browser_action": {
        "default_icon": "icon128.png",
        "default_title": "EXTENSTION DESCRIPTION",
        "default_popup": "extension.html"
  },

  "permissions": 
     ["tabs"]
}

我唯一想做的就是在新选项卡上打开网站。

最佳答案

也许这可以帮助你。

ma​​nifest.json

{ "name": "Name of extension",
  "version": "0.1",
  "manifest_version": 2, 
  "description": "Opens Tab!",
  "browser_action": {
        "default_icon": "icon128.png"
  },
  "icons": {
            "48": "icon128.png"
            },
    "background":{
                    "scripts": ["background.js"]
    }
}

背景.js

chrome.browserAction.onClicked.addListener(function(activeTab) {
    var newURL = "http://www.google.nl";

    chrome.tabs.create({ url: newURL });
});

背景.html

<html>
<head>
</head>
<body>
<h1>Hello people</h1>
<br />
<p>Hello fellow pele</p>
</body>
</html>

希望我的回答对你有帮助。

关于javascript - Google Chrome 扩展程序打开网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23304370/

相关文章:

javascript - 正则表达式转义括号

javascript - 如何让 javascript 警报在 gmail/outlook 中工作

javascript - 从外部或内部 div 动态加载内容到 div

html - Flex/Grid 布局不适用于按钮或字段集元素

jQuery:从字符串数组创建多个跨度

java - 如何在 CRONET 中将 json 对象作为 post 请求发送?

Javascript 作用域和闭包,变量保持其值

video - HTML5 视频 : Force abort of buffering

html - 为什么在 Chrome 中转换字体大小如此不稳定?

google-chrome - 无法加载资源:net::ERR_INCOMPLETE_CHUNKED_ENCODING