从Chrome应用程序窗口打开另一个Chrome应用程序窗口 [英] open another chrome app window from a chrome app window

查看:189
本文介绍了从Chrome应用程序窗口打开另一个Chrome应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录窗口,作为Chrome安装的扩展程序打开(将是一个独立的Chrome网页应用程序,因此我使用manifest.json来设置.js文件,然后打开小登录窗口。 p>

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



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

b
$ b

这里是我的代码,每个都有,不带CSS。






清单.json

  {
name:CAD,
description:CAD呼叫表,
manifest_version:2,
minimum_chrome_version:23,
版本:0.1,
offline_enabled:true,
app:{
background:{
scripts:[mainInfo.js]
}
},

图标:{
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>登入< / title>
< link rel ='stylesheet'href =CADLogin.csstype ='text / css'/>
< script type =text / javascriptsrc =CADLogin.js>< / script>
< / head>

< body>
< header>
< h1 class =loginHeader> CAD登入< / h1>
< / header>

< form id =loginForm>
< br />
< div id =loginUsernamediv>
< input class =loginFieldstype =textid =loginUsernamename =loginUsernameplaceholder =Username/>
< / div>

< div id =loginPassworddiv>
< input class =loginFieldstype =passwordid =loginPasswordname =loginPasswordplaceholder =Password/>
< / div>

< br />

< div id =loginButtonsdiv>
< button class =loginButtonid =loginButton>
登入
< / button>
< button class =loginButtonid =cancelButton>
取消
< / 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
});
}
}
}

任何帮助表示赞赏。 / p>

解决方案

好的,在我的代码中检查Typos有帮助。 texxt / javascript和text / javascript不一样...第一个实际上会使代码无法工作。


I have a login window that I open as a Chrome installed Extension (will be a stand-alone chrome web app, so I use the manifest.json to setup the .js file which then opens the little login window.

I want it so that when the user enters correct credentials, and clicks login, I can then open the main application window.

My login window opens fine, but can't get the next window to open. I'm sure this has something to do with sandboxing, but I don't know where I'm going wrong.

Here's my code for each so far, w/o 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
            });
        }
    }
}

Any help is appreciated.

解决方案

Ok, so checking for Typos in my code helps. texxt/javascript and text/javascript aren't the same...and the first will actually make the code not work.

这篇关于从Chrome应用程序窗口打开另一个Chrome应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆