更改弹出窗口的高度

问题描述 投票:0回答:4

当我单击扩展程序图标时,会出现一个弹出窗口,但我面临的问题是弹出窗口高度太大,因此它位于我的任务栏下方。有没有办法设置弹出窗口的高度?

我尝试过通过 body 标签在 css 文件中声明高度和宽度。但只有窗口的宽度发生变化。我也尝试过制作 iframe,但弹出窗口只是空白。

google-chrome-extension
4个回答
12
投票

在弹出页面的开头添加以下内容以替换

<html>

<!DOCTYPE html>

祝你好运!


6
投票

您可以使用 window.resizeTo(preferedWidth, PreferredHeight) 函数设置弹出窗口的高度和宽度。如果你想在弹出窗口中设置它而不是从父窗口而不是 self.resizeTo(preferedWidth, PreferredHeight);将为您完成这项工作。

更好的建议是将您的内容保存在 div 中,例如 id 为“content”的 div,这样您就可以将其用于弹出窗口。

<head>
<script type="text/javascript">
function resizeMe()
{
    height = document.getElementById("content").offsetHeight;
    width  = document.getElementById("content").offsetWidth;
    self.resizeTo(width+20, height+100);
}
</script>
</head>

<body onload="resizeMe();">

这应该足以解决您的问题。


0
投票

尝试:

<style type="text/css">
    body {
       max-height: 300px;
    }
</style>

or just,

<style type="text/css">
    body {
       height: 300px;
    }
</style>

在 popup.html 的

<head>
标签中。


0
投票

这对我有用:

chrome.windows.create({
    type: 'popup', 
    width: 400, 
    height: 300, 
},)
© www.soinside.com 2019 - 2024. All rights reserved.