【发布时间】:2017-07-19 17:06:07
【问题描述】:
我是 chrome 应用程序编程和 stackoverflow 的新手。
我有一个简单的 chrome 应用程序,我想在其中将多个网站嵌入到单独的 webviews 中,这些 webviews 会根据用户创建应用程序窗口的大小自动缩放,同时保持每个 web 视图的比例。这样一来,无论应用程序在所有内容显示上显示什么尺寸的屏幕。
我可以使用下面的代码让它在一个 webview 上工作,但是我不知道如何嵌入多个站点。
清单.json { "name": "Hello World!", "description": "我的第一个 Chrome 应用程序。", “版本”:“0.1”, “清单版本”:2, “权限”:[“网络视图”], “图标”:{ “128”:“标志.png” }, “应用程序”: { “背景”: { “脚本”:[“background.js”] } } }
background.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
bounds: {
'width': 1380,
'height': 1700
}
});
})
index.html
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0px;
}
</style>
</head>
<body>
<webview id="wv1" src="http://www.google.com"></webview>
<script src="main.js"></script>
</body>
</html>
main.js
function updateWebviews() {
var webview = document.querySelector("webview");
webview.style.width = document.documentElement.clientWidth + "px";
};
onload = updateWebviews;
window.onresize = updateWebviews;
【问题讨论】:
标签: javascript html webview google-chrome-app