我正在尝试使用 window.open 函数在弹出窗口中打开聊天脚本。
这是我所拥有的;
function openWindow(url,width,height,name)
{
width = width ? width : 725;
height = height ? height : 600;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', resizable=yes';
name = name ? name : 'Chat';
window.open(url,name,params);
}
这是实际加载内容的ajax调用(由按钮触发);
function chat(id)
{
$.ajax
({
type: "POST",
url: "includes/chat/process.php",
data: {
'function': 'initiate',
'user-id': id
},
dataType: "json",
success: function(data)
{
if(data.available == true)
openWindow("includes/chat/chat.php");
else if(data.available == false)
alert("Not available");
},
});
}
当我运行它时,它会很好地加载 chat.php,但是由于某种原因,窗口会在我的 html 中添加额外的顶部填充。
我尝试了一切我能想象的方法来删除它,但没有成功。我的所有 css 文件的 body 和 html 元素都有边距和填充“0”。
最佳答案
通常,如果您在 Console 或 Firebug 中检查页面,您应该能够知道额外填充的来源。它分解了它所来自的所有 CSS 文件。
关于javascript window.open 不必要的顶部填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8013947/