在同一Chrome应用窗口中打开HTML文件?

时间:2016-06-06 22:24:03

标签: javascript css json html5 google-chrome-app

阿罗哈,

我正在尝试制作替换Chrome Dev Editor的Chrome App。这是我目前的情况:

background.js

chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('backstage.html', {
    'outerBounds': {
        'width': 1036,
        'height': 583
    }
  }); 
});

backstage.html

<!DOCTYPE html>
<html>
<head>
    <title>Celestia Pro</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel = "stylesheet" href = "material.css">
    <link rel = "stylesheet" href = "material.min.css">
    <link rel = "stylesheet" href = "styles.css">
</head>

<body>
<!-- The drawer is always open in large screens. The header is always shown,
  even in small screens. -->
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer
            mdl-layout--fixed-header">
  <header class="mdl-layout__header">
    <div class="mdl-layout__header-row">
      <div class="mdl-layout-spacer"></div>
      <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable
                  mdl-textfield--floating-label mdl-textfield--align-right">
        <label class="mdl-button mdl-js-button mdl-button--icon"
               for="fixed-header-drawer-exp">
          <i class="material-icons">search</i>
        </label>
        <div class="mdl-textfield__expandable-holder">
          <input class="mdl-textfield__input" type="text" name="sample"
                 id="fixed-header-drawer-exp">
        </div>
      </div>
    </div>
  </header>
  <div class="mdl-layout__drawer">
    <span class="mdl-layout-title">Title</span>
    <nav class="mdl-navigation">
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
      <a class="mdl-navigation__link" href="">Link</a>
    </nav>
  </div>
  <main class="mdl-layout__content">
    <div class="page-content">
<style>
.demo-card-wide.mdl-card {
  width: 100%;
}
.demo-card-wide > .mdl-card__title {
  color: #fff;
  height: 176px;
  background: url('welcome-card.jpg') center / cover;
}
.demo-card-wide > .mdl-card__menu {
  color: #fff;
}

div.start-cards {
    padding-top: 25px;
    padding-left: 50px;
    padding-right: 50px;
}
</style>

<div class="start-cards" align = center>
<div class="demo-card-wide mdl-card mdl-shadow--2dp">
  <div class="mdl-card__title">
    <h2 class="mdl-card__title-text">Welcome to Celestia Pro</h2>
  </div>
  <div class="mdl-card__supporting-text">
    Celestia Pro is a new integrated development environment (IDE) that allows developers to create Chrome apps quickly and efficiently. We're still in our baby stages, but we hope this tool works for you.
  </div>
  <div class="mdl-card__actions mdl-card--border">
    <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" onclick="runWizard()">
      Get Started
    </a>
    <script>

    </script>
  </div>
    </button>
  </div>
</div>

    </div>
  </main>
</div>
</div>
    <script src = "./material.min.js">
    <script src = "./material.js">

</body>
</html>

在我尝试使用开始按钮之前,这似乎一切都很好,我提到实际打开的东西。我希望它打开一个名为&#39; backstage2.html&#39;的页面,但无论我尝试什么组合,它似乎都不起作用。这是我尝试过的。

这些似乎都不起作用。我希望能够在相同的Chrome应用窗口中打开backstage2.html!如果可能的话,我怎么能这样做呢?非常感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

您可能希望使用Web组件并将文件导入主文件中。然后,您可以将其用作常规Web组件。 其他选项是将请求发送到后台页面,您可以在其中保存对已打开窗口的引用。此引用具有contentWindow属性,该属性是JavaScript的window对象。您可以使用它来替换man窗口的内容(在使用例如fetch读取新文件数据之后)。

答案 1 :(得分:0)

使用href =&#34;你的html文件&#34; target =&#34; _self&#34;

答案 2 :(得分:0)

您可以webview使用backstage.html (或在新窗口中)

可能......

<强> backstage.html

<a id="wizard" class="···">Get Started</a>
<!-- onclick doesn't work by CSP (see note bellow) ··· -->
<webview></webview>
<!-- ··· -->
<script src="./main.js"></script>

<强> main.js

onload = function {
  // ···
  document.querySelector('#wizard').addEventListener('click', runWizard);
  // ···
};
// ···
function runWizard() {
  // ···
  document.querySelector('webview').src = 'backstage2.html';
  // ···
};

CSP - 内容安全政策 - ,请注意: “You can’t use inline scripting ...”

@abarisone:谢谢!