窗口.使用搜索打开

Window.Open with Search

本文关键字:搜索 窗口      更新时间:2023-09-26

我有以下窗口打开方法:

                    <script>
                    function searchForm(form){
                        window.open("test.php?Search=", "newwindow", "scrollbars=yes", "width=800", "height=600", + form.s.value)
                        return false;
                    }
                </script>
                <form method="get" onsubmit="return searchForm(this)" class="form-inline" role="form" />
                    <div class="form-group">
                        <input class="form-control input-sm" name="s" type="text" onFocus="if (this.value == 'Search Events') {this.value='';" />
                    </div>
                        <button type="submit" class="btn btn-text">Lookup Existing Data</button>            
                </form>

我希望使用上面的参数打开新窗口,但是当我添加它们时,它会破坏搜索中的数据,如果我删除参数值,它可以工作,但窗口在新选项卡中打开。

您需要将数据

附加到 URL!您正在推送代码以将字符串追加为其自己的参数,而不是作为构造 URL 的语句的一部分。

此外,窗口描述参数需要作为单个参数传递。

最后,在将用户输入转换为数据格式(如 URL)时,您需要对其进行转义。

window.open(
  "test.php?Search=" + encodeURIComponent(form.s.value),
  "newwindow",
  "scrollbars=yes,width=800,height=600"
);