首次安装Chrome扩展程序后,通过使用私有企业chrome应用程序扩展程序中的.crx文件,打开“设置”页面

时间:2018-07-17 06:07:14

标签: javascript google-chrome-app

在使用extension中的.crx文件安装chrome插件时,我只想第一次显示设置页面。以下字段将需要填写:

1)TID(textbox)
2)SID(textbox)
3)TLocation(textbox) 
4)BaseURL(for web service API)

此数据将被存储,用户将来也可以更改此设置。

如何使用.crx文件在安装后显示此页面,该应用程序将仅是私有应用程序。

当前,我正在使用webview在chrome应用中显示我们的网站,如下所示:

<webview src="http://yoursite.com/chromeapp" style="width:100%; height:90%"></webview> 

我在google上搜索并找到了以下方法,但是它不适用于.crx安装,我认为这仅适用于公共应用程序

  chrome.runtime.onInstalled.addListener(function (object) {
  chrome.tabs.create({url: "http://yoursite.com/"}, function (tab) {
    console.log("New tab launched with http://yoursite.com/");
   });
 });

我的JS文件代码:

 chrome.app.runtime.onLaunched.addListener(function() {
  runApp();
 });


 chrome.app.runtime.onRestarted.addListener(function() {
  runApp();
  });

chrome.runtime.onInstalled.addListener(function (object) {
  chrome.tabs.create({url: "http://yoursite.com/setting.html"}, function (tab) 
  {
    console.log("called: http://yoursite.com/setting.html");
  });
  });

  function runApp() {
       chrome.app.window.create('browser.html', {
          bounds: {
          'width': 1024,
          'height': 768
         }
         });
       }

如果有人进行过此类工作,请提供帮助。

1 个答案:

答案 0 :(得分:0)

请尝试下面的代码,它肯定会适合您的情况。

Background.js

chrome.runtime.onInstalled.addListener(function (details) {
  if (details.reason == "install") {
    runSettingApp();
  } else {
    runApp();
    }
});

创建两个函数。首先将在首次安装时打开设置屏幕,然后将其在启动时打开主页。

function runApp() {
chrome.app.window.create('home.html', {
bounds: {
  'width': 1024,
  'height': 768
  }
 });
}

function runSettingApp() {
chrome.app.window.create('setting.html', {
bounds: {
  'width': 1024,
  'height': 768
 }

 });
}