javascript window.open不必要的top-padding

时间:2011-11-04 18:14:46

标签: javascript ajax popup

我正在尝试使用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,但由于某种原因,窗口会将额外的top-padding添加到我的html中。

我尝试了一切我能想象的去除它,但没有运气。我的所有css文件都有一个边距,并为body和html元素填充“0”。

2 个答案:

答案 0 :(得分:1)

您可以尝试使用yahoo css在浏览器中正确控制某些方面。

http://www.yahooapis.com/yui/reset/

答案 1 :(得分:1)

通常,如果您在Console或Firebug中检查页面,您应该能够知道额外填充的来源。它分解了它来自哪个文件的CSS。