admin管理员组文章数量:1287147
I am building a chrome app, which will simply open a link, for example "/" in a new tab in chrome.
I have the following code in my manifest.json
{
"manifest_version": 2,
"name": "CNN",
"version": "2.1",
"permissions": ["webview", "pointerLock", "geolocation", "videoCapture"],
"app": {
"background": {
"scripts": ["main.js"]
}
}
}
And this is what i have in main.js:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('/', {
});
});
I have also tried,
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create({ "url": "" });
});
as well as:
chrome.app.runtime.onLaunched.addListener(function(tab) {
chrome.app.tab.create({ "url": "" });
});
PLease help.
Thank you
I am building a chrome app, which will simply open a link, for example "http://www.cnn./" in a new tab in chrome.
I have the following code in my manifest.json
{
"manifest_version": 2,
"name": "CNN",
"version": "2.1",
"permissions": ["webview", "pointerLock", "geolocation", "videoCapture"],
"app": {
"background": {
"scripts": ["main.js"]
}
}
}
And this is what i have in main.js:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('http://www.cnn./', {
});
});
I have also tried,
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create({ "url": "http://cloudsupport.neonova/home" });
});
as well as:
chrome.app.runtime.onLaunched.addListener(function(tab) {
chrome.app.tab.create({ "url": "http://cloudsupport.neonova/home" });
});
PLease help.
Thank you
Share Improve this question edited Mar 27, 2014 at 4:56 Derek 朕會功夫 94.4k45 gold badges197 silver badges253 bronze badges asked Mar 27, 2014 at 4:44 user3464774user3464774 631 silver badge3 bronze badges 5- Why are you building an app for just opening link? – Ale Commented Mar 27, 2014 at 4:50
- you want page to open whenever chrome opens up? – Muhammad Umer Commented Mar 27, 2014 at 4:58
- where is tab permission? shouldn't you have it – Muhammad Umer Commented Mar 27, 2014 at 4:58
- ALso what is happening when you run this code – Muhammad Umer Commented Mar 27, 2014 at 5:02
- @MuhammadUmer I want the page to open when I launch the app. I added the tab permission. When I double click on the app from Chrome:Apps , the page that is open "Chrome:Apps" closes and that's it. – user3464774 Commented Mar 27, 2014 at 12:05
3 Answers
Reset to default 6Anyway, I've tried window.open
and it forked like a charm:
'use strict';
chrome.app.runtime.onLaunched.addListener(function() {
window.open("https://google./");
});
So it might work for you as well.
As of chrome 42, chrome.browser may help:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.browser.openTab({
url: 'https://google./'
});
});
Reference: https://developer.chrome./extensions/tabs#method-create
var options= { url: "http://cloudsupport.neonova/home" };
chrome.app.runtime.onLaunched.addListener(function() {
chrome.tabs.create(options);
});
then in manifest.json. add this permission.
...
"permissions": ["tabs","webview", "pointerLock", "geolocation", "videoCapture"]
...
本文标签: javascriptChrome appopen link in a new tabStack Overflow
版权声明:本文标题:javascript - Chrome app, open link in a new tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741307068a2371432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论