【问题标题】:open another chrome app window from a chrome app window [closed]从 chrome 应用程序窗口打开另一个 chrome 应用程序窗口 [关闭]
【发布时间】:2012-11-20 18:05:40
【问题描述】:

我有一个作为 Chrome 安装扩展程序打开的登录窗口(将是一个独立的 chrome web 应用程序,所以我使用 manifest.json 设置 .js 文件,然后打开小登录窗口。

我希望这样当用户输入正确的凭据并单击登录时,我可以打开主应用程序窗口。

我的登录窗口可以正常打开,但无法打开下一个窗口。我确定这与沙盒有关,但我不知道我哪里出错了。

到目前为止,这是我的代码,没有 CSS。


manifest.json

{
    "name": "CAD",
    "description": "A CAD Call Sheet",
    "manifest_version": 2,
    "minimum_chrome_version": "23",
    "version": "0.1",
    "offline_enabled": true,
    "app": {
        "background": {
            "scripts": ["mainInfo.js"]
        }
    },

    "icons": {
        "16": "assets/icon-128x128.png",
        "128": "assets/icon-128x128.png"
    }
}

mainInfo.js

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('CADLogin.html', {
    width: 250,
    height: 250,
    maxWidth: 250,
    minWidth: 250,
    minHeight: 250,
    maxHeight: 250,
  });
});

CADLogin.html

<!DOCTYPE html>
<html>
    <head>
        <title>Login</title>
        <link rel='stylesheet' href="CADLogin.css" type='text/css' />
        <script type="text/javascript" src="CADLogin.js"></script>
    </head>

    <body>
        <header>
            <h1 class="loginHeader">CAD Login</h1>
        </header>

        <form id="loginForm">
            <br />
            <div id="loginUsernamediv">
                <input class="loginFields" type="text" id="loginUsername" name="loginUsername" placeholder="Username" />
            </div>

            <div id="loginPassworddiv">
                <input class="loginFields" type="password" id="loginPassword" name="loginPassword" placeholder="Password" />
            </div>

            <br />

            <div id="loginButtonsdiv">
                <button class="loginButton" id="loginButton">
                    Login
                </button>
                <button class="loginButton" id="cancelButton">
                    Cancel
                </button>
            </div>

            <br />
            <br />

        </form>
    </body>

</html>

CADLogin.js

window.onload = function() {

    document.getElementById("cancelButton").onclick = function() {
        window.close();
    }

    document.getElementById("loginButton").onclick = function() {
        var username = document.getElementById("loginUsername");
        var password = document.getElementById("loginPassword");
        if (username=="brian" && password=="letmein") {
            chrome.app.window.create('MainSelections.html', {
                width: 100,
                height: 250,
                maxWidth: 100,
                minWidth: 100,
                minHeight: 250,
                maxHeight: 250
            });
        }
    }
}

感谢任何帮助。

【问题讨论】:

    标签: google-chrome window manifest


    【解决方案1】:

    好的,因此检查我的代码中的错别字会有所帮助。 texxt/javascript 和 text/javascript 不一样...第一个实际上会使代码不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      相关资源
      最近更新 更多