Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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应用程序在Webview中添加点击事件按钮/输入_Javascript_Html_Google Chrome Extension_Webview_Google Chrome App - Fatal编程技术网

Javascript Chrome应用程序在Webview中添加点击事件按钮/输入

Javascript Chrome应用程序在Webview中添加点击事件按钮/输入,javascript,html,google-chrome-extension,webview,google-chrome-app,Javascript,Html,Google Chrome Extension,Webview,Google Chrome App,我制作了这个chrome应用程序,它使用webview从某个链接加载内容。我的问题是我不知道如何将单击或其他事件添加到元素中,例如按钮。 我需要使用webview,因此在扩展中构建内容不是一个选项。 我还需要与webview元素进行通信/更改,因为我需要从USB设备获取数据,并在webview中填充一些输入 我要么尝试了我发现的一切,但没有运气,要么做得很糟糕 谢谢 这是包中的my index.html <head> <meta charset="utf-8"> <

我制作了这个chrome应用程序,它使用webview从某个链接加载内容。我的问题是我不知道如何将单击或其他事件添加到元素中,例如按钮。 我需要使用webview,因此在扩展中构建内容不是一个选项。 我还需要与webview元素进行通信/更改,因为我需要从USB设备获取数据,并在webview中填充一些输入

我要么尝试了我发现的一切,但没有运气,要么做得很糟糕

谢谢

这是包中的my index.html

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="app.css">
<link rel="stylesheet" href="reset.css">
<script src="jquery.js"></script>
</head>
<body>

<webview id="webview" partition="persist:googlepluswidgets" style="width: 100%; height: 100%;" class="full trim"  src="http://urlOfApplication.com" ></webview>

<script src="main.js"></script>
<script src="port.js"></script>
<script src="printer.js"></script>
</body>
background.js

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

    chrome.app.window.create('popup.html', {
        // 'id': 'amanet-app',
        'state' : 'maximized',
        'resizable' : true,
        'alwaysOnTop' : false,
        state: 'maximized'
    },
    function(win) {
        win.maximize();
        // win.clearAttention();
        // win.restore();
    }
    );

});

chrome.app.window.onClosed.addListener(function() {
  // Do some simple clean-up tasks.
  $.ajax({url:"http://tezaur-local/auth/logout", async:false});
  //var expires = new Date();
//  expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
    //document.cookie = 'laravel_session=;path=/;expires=' + expires.toUTCString();
});

//chrome.app.window.canSetVisibleOnAllWorkspaces(false);
一种方法是在
webview
内部运行,因为它可以访问
webview
的DOM

例如:

document.querySelector('webview').executeScript({
  code: 'document.getElementById("button-id").onclick = function() { /* click handler */ }',
  function(results) { if (results && results.length) { /* successful script injection */ }
});
document.querySelector('webview').executeScript({
  code: 'document.getElementById("button-id").onclick = function() { /* click handler */ }',
  function(results) { if (results && results.length) { /* successful script injection */ }
});