Awe*_*ena 2 google-chrome-extension google-chrome-app
我正在测试<webview>
Chrome中的元素并且我已经阅读了文档,但我无法弄清楚为什么Webview
在父窗口时没有调整大小.
INDEX.HTML
<body>
<webview src="http://website.com" style="width:1010px; height:700px" minwidth="1010" minheight="700" autosize="on""></webview>
<script src="index.js"></script>
Run Code Online (Sandbox Code Playgroud)
background.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
'bounds': {
'width': 1010,
'height': 700
}});});
Run Code Online (Sandbox Code Playgroud)
Index.js
$(function() {
function resizeWebView() {
$('webview').get(0).width = $(window).width();
$('webview').get(0).height = $(window).height();
}
$(window).resize(resizeWebView);
resizeWebView();
});
Run Code Online (Sandbox Code Playgroud)
我也尝试删除autosize=on
推荐但不起作用.另一个问题是如何禁用主窗口(Embedder)来调整大小.谢谢
您应该chrome.app.window.onBoundsChanged
在返回的窗口对象上使用API chrome.app.window.create
.简单实施:
background.js
var appWin = null;
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create(
'index.html',
{'bounds': {'width': 1010, 'height': 700}},
onWindowCreated
);
});
function onWindowCreated(win) {
appWin = win;
// Resize the webview when the window resizes.
appWin.onBoundsChanged.addListener(onBoundsChanged);
// Initialize the webview size once on launch.
onBoundsChanged();
}
function onBoundsChanged() {
var webview = document.querySelector('webview');
var bounds = appWin.getBounds();
webview.style.height = bounds.height + 'px';
webview.style.width = bounds.width + 'px';
}
Run Code Online (Sandbox Code Playgroud)
index.js
// Nothing here
Run Code Online (Sandbox Code Playgroud)
查看具有多个窗口的更精细的面向对象示例,并持久/重用用户在此处设置的最后一个窗口大小:https://github.com/GoogleChrome/chrome-app-samples/tree/master/url-handler.
至于你的第二个问题,如果你单独提出它会很好,但是:只需将resizable
参数设置chrome.app.window.create
为false:
...
chrome.app.window.create(
'index.html',
{
'bounds': {'width': 1010, 'height': 700},
'resizable': false
},
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2769 次 |
最近记录: |