Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的chrome扩展中的chrome开发工具等停靠/解锁功能_Javascript_Html_Google Chrome_Google Chrome App - Fatal编程技术网

Javascript 我的chrome扩展中的chrome开发工具等停靠/解锁功能

Javascript 我的chrome扩展中的chrome开发工具等停靠/解锁功能,javascript,html,google-chrome,google-chrome-app,Javascript,Html,Google Chrome,Google Chrome App,我正在创建一个google chrome扩展,它将加载我的web应用程序。我有一个地图组件,我希望这个地图组件可以附加/取消附加(当用户从其位置拖动它时,它将在新窗口中打开自己,或者当用户关闭地图窗口时,它将附加到我的主应用程序) main.js chrome.app.runtime.onLaunched.addListener(function() { // Center window on screen. var screenWidth = screen.availWidth

我正在创建一个google chrome扩展,它将加载我的web应用程序。我有一个地图组件,我希望这个地图组件可以附加/取消附加(当用户从其位置拖动它时,它将在新窗口中打开自己,或者当用户关闭地图窗口时,它将附加到我的主应用程序)

main.js

chrome.app.runtime.onLaunched.addListener(function() {
    // Center window on screen.
    var screenWidth = screen.availWidth;
    var screenHeight = screen.availHeight;
    var width = 500;
    var height = 300;

    chrome.app.window.create('index.html', {
        id: "helloWorldID",
        outerBounds: {
          width: width,
          height: height,
          left: Math.round((screenWidth-width)/2),
          top: Math.round((screenHeight-height)/2)
        }
    });

    chrome.app.window.onClosed.addListener(function(e) {
        console.log(e)
    });
    chrome.app.window.onFullscreened.addListener(function(e) {
        console.log(e)
    })


});
index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello World</title>
    <link href="styles/main.css" rel="stylesheet">
    <style type="text/css">
    .innermenu {
        width: 200px;
        height: 200px;
        background: #f00;
    }
    </style>
    <script type="text/javascript" src="jquery-2.1.3.js"></script>
    <script type="text/javascript" src="jquery-ui.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body>
    <h1>Main File</h1>
    <div id="menu">
        <div class="innermenu">MAP</div>    
    </div>
</body>
</html>

所以我的问题是如何在map.html(在单独的窗口中打开)和index.html(我的主应用程序)之间进行通信。

首先,非常重要的是,您拥有的不是一个扩展,而是一个应用程序。这是一套完全不同的规则。你到底有什么问题?如中所示,当用户关闭“地图”时,@Xan I want不包括什么?然后我想向main.js发送通知,但我无法获得地图的关闭事件。
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
var width = 500;
var height = 300;
var id = 1;
$(document).ready(function(){

    $("#menu").sortable({
        out: function( event, ui ) {
            chrome.app.window.create('map.html', {
                id: "map" + (id++),
                outerBounds: {
                    width: width,
                    height: height,
                    left: Math.round((screenWidth-width)/2),
                    top: Math.round((screenHeight-height)/2)
                }
            });
        }
    });
});