从Chrome应用窗口打开另一个Chrome应用窗口

时间:2012-11-20 18:05:41

标签: google-chrome window manifest

我有一个登录窗口,我作为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
            });
        }
    }
}

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

好的,所以在我的代码中检查Typos有帮助。 text / javascript和text / javascript不一样......第一个实际上会使代码不起作用。

相关问题