Google Chrome扩展程序打开网址

时间:2014-04-25 22:51:25

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

所以我有点新的扩展,所以我想从一个简单的开始。好吧,我认为这不是太难,但我无法在隐身和正常情况下打开新的标签页。

POPUP PAGE:

    <!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>

我的清单文件:

{
  "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"]
}

我唯一想做的就是在新标签页上打开网站。

1 个答案:

答案 0 :(得分:1)

好吧,这可以帮到你。

<强>的manifest.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"]
    }
}

<强> background.js

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

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

<强> background.html

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

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