【问题标题】:Trouble with opening new window in javascript在javascript中打开新窗口的问题
【发布时间】:2019-07-31 13:31:40
【问题描述】:

我正在尝试使用一些 JavaScript 在 Chrome 中打开新窗口:

var windowTask = window.open("http://localhost/testapp/site/windows/formTask.html", "taskForm", "width=800, height=500, toolbar=yes, menubar=yes, scrollbars=no");

但是,当它打开时,它没有菜单栏和工具栏,但它有滚动条。我做错了什么?

完整代码为:

<div id="box" style="height:90%; width:100%;">
            <script>
                dtable = new webix.ui({
                container:"box",
                view:"datatable",
                columns:[
                    { id: "taskID", header: "Task ID", fillspace: true},
                    { id: "title", header: "Title", fillspace: true},
                    { id: "status", header: "Status", fillspace: true},
                    { id: "creator", header: "Creator", fillspace: true},
                    { id: "description", header: "Description", fillspace: true},
                    { id: "responsible", header: "Responsible", fillspace: true},
                    { id: "dateCreation", header: "Date creation", fillspace: true},
                    { id: "dateStart", header: "Date start", fillspace: true},
                    { id: "dateFinish", header: "Date finish", fillspace: true}
                    ],
                    url:"http://localhost/testapp/php/tasks/getTaskList.php",
                    select:"row",
                    on:{"onItemDblClick": function () {
                        var selectedRow = dtable.getSelectedItem();
                        var windowTask = window.open("http://localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=1,menubar=1,scrollbars=0");
                        windowTask.onload = function(){
                            windowTask.document.getElementById("taskID").value = selectedRow.taskID;
                            windowTask.document.getElementById("title").value = selectedRow.title;
                            windowTask.document.getElementById("status").value = selectedRow.status;
                            windowTask.document.getElementById("creator").value = selectedRow.creator;
                            windowTask.document.getElementById("responsible").value = selectedRow.responsible;
                            windowTask.document.getElementById("description").value = selectedRow.description;
                            windowTask.document.getElementById("dateCreation").value = selectedRow.dateCreation;
                            windowTask.document.getElementById("dateStart").value = selectedRow.dateStart;
                            windowTask.document.getElementById("dateFinish").value = selectedRow.dateFinish;
                        }                        
                    }}
                });
            </script>
        </div>

总结:

在 Mozilla 中此代码:

var windowTask = window.open("localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=1,menubar=1,scrollbars=0");

工作正常,但在 Chrome 中:

var windowTask = window.open("localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=1,menubar=1,scrollbars=0");

还有这个:

var windowTask = window.open("localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=true,menubar=true,scrollbars=false");

还有这个:

var windowTask = window.open("localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=yes,menubar=yes,scrollbars=no");

仍然没有给我菜单栏和工具栏,并且启用了滚动条。怎么了?

【问题讨论】:

  • 如果您需要真正的窗口功能,只需在新选项卡中打开它即可。这样,您将拥有所需的一切。要在新选项卡中打开它,只需从字符串中省略宽度和高度。

标签: javascript


【解决方案1】:

根据规范,选项字符串应该有 no 空格。

一个 DOMString 包含一个以逗号分隔的窗口特征列表,并以“name=value”的形式给出它们的对应值。这些功能包括诸如窗口的默认大小和位置、是否包括滚动条等选项。字符串中不能有空格。有关可以指定的每个功能的文档,请参阅下面的 Window 功能。

我已经在下面相应地调整了你的线路。

var windowTask = window.open(
  "http://localhost/testapp/site/windows/formTask.html",
  "taskForm",
  "width=800,height=500,toolbar=yes,menubar=yes,scrollbars=no"
);

【讨论】:

    【解决方案2】:

    您是否尝试将其更改为menubar=1toolbar=1menubar=truetoolbar=true。将滚动条更改为 scrollbars=0 将禁用滚动条。它们也不应包含任何空格。

    最终代码应如下所示:

    window.open("http://localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=yes,menubar=yes,scrollbars=no");

    【讨论】:

    • 根据文档,任何一个都应该工作:developer.mozilla.org/en-US/docs/Web/API/Window/…
    • 我现在试试,结果还是一样。仍然没有菜单栏和工具栏,但滚动条已打开。
    • 你删除了空格吗?喜欢@vivalldi 发布的内容吗?
    • 是的,我在结果中使用了这个代码: var windowTask = window.open("localhost/testapp/site/windows/formTask.html", "taskForm", "width=800,height=500,toolbar=1,menubar=1 ,滚动条=0");但是,在 Mozilla 中它完全正确,没有滚动条、菜单栏和工具栏。
    • windowTask 是否在某个按钮或某处被调用?你确定你正确地调用了这个变量吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多