Chrome应用,在新标签页中打开链接

时间:2014-03-27 04:44:17

标签: javascript google-chrome google-chrome-app

我正在构建一个Chrome应用,它只会打开一个链接,例如" http://www.cnn.com/"在Chrome中的新标签页中。

我的manifest.json

中有以下代码
{
  "manifest_version": 2,
  "name": "CNN",
  "version": "2.1",
  "permissions": ["webview", "pointerLock", "geolocation", "videoCapture"],
  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  }
}

这就是我在main.js中所拥有的:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('http://www.cnn.com/', {

  });
});

我也试过了,

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create({ "url": "http://cloudsupport.neonova.net/home" });
});

以及:

chrome.app.runtime.onLaunched.addListener(function(tab) {
  chrome.app.tab.create({ "url": "http://cloudsupport.neonova.net/home" });
});

提供帮助。

谢谢

3 个答案:

答案 0 :(得分:5)

无论如何,我已经尝试window.open并且它像一个魅力一样分叉:

'use strict';

chrome.app.runtime.onLaunched.addListener(function() {
    window.open("https://google.com/");
});

所以它也适用于你。

答案 1 :(得分:5)

从第42号铬开始,chrome.browser可能会有所帮助:

mysql> CREATE TABLE t (a VARCHAR(8000), b VARCHAR(10000),
    -> c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000),
    -> f VARCHAR(10000), g VARCHAR(10000)) ENGINE=InnoDB;
ERROR 1118 (42000): Row size too large. The maximum row size for the
used table type, not counting BLOBs, is 65535. You have to change some
columns to TEXT or BLOBs

答案 2 :(得分:-3)

参考: https://developer.chrome.com/extensions/tabs#method-create

var options= { url: "http://cloudsupport.neonova.net/home" };

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.tabs.create(options);
});

然后在manifest.json中。添加此权限。

...
"permissions": ["tabs","webview", "pointerLock", "geolocation", "videoCapture"]
...