Javascript Window.Open POST

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5554896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:46:51  来源:igfitidea点击:

Window.Open POST

javascriptjquerypostpopupwindow.open

提问by Pit Digger

I have a link which when clicked I open a window with window.open like below.

我有一个链接,单击该链接时会打开一个带有 window.open 的窗口,如下所示。

 window.open("edit.jsp?clientId=" + clientId + "&eventId=" + eventId , 'height=600,width=800,scrollbars=1,location:no,menubar:no,resizable=1,status:no,toolbar:no');

I dont want the parameter to pass here instead I want to something like post so people cant copy url .

我不希望参数在这里传递,而是我想要像 post 这样的东西,所以人们不能复制 url 。

回答by Evert

You cannot trigger a javascript popup and then force a post request.

您不能触发 javascript 弹出窗口然后强制发布请求。

Three options:

三个选项:

  1. Trigger a POST form with target="_blank"using javascript (but this doesn't allow you to disable interface elements such as the menu bar).
  2. Open a popup locally, but don't specify a url. Use the result of window.open to alter the document to generate a form, which you'd then post.

    var myWindow = window.open("", "", "height=600,width=800,scrollbars=1,location=no,menubar=no,resizable=1,status=no,toolbar=no");
    myWindow.document.write("Write a form here and then later on trigger it");
    
  3. You really shouldn't do any of this. If it's bad for users to copy urls, there's a flaw in your application design.

  4. Added after edit: Use the 'empty window' approach, but instead of writing a form and triggering it, do a an XMLHTTPRequest(with POST) in the parent. The result of this request can be used to populate the child-window.

  1. target="_blank"使用 javascript触发 POST 表单(但这不允许您禁用菜单栏等界面元素)。
  2. 在本地打开一个弹出窗口,但不要指定 url。使用 window.open 的结果来更改文档以生成一个表单,然后您将发布该表单。

    var myWindow = window.open("", "", "height=600,width=800,scrollbars=1,location=no,menubar=no,resizable=1,status=no,toolbar=no");
    myWindow.document.write("Write a form here and then later on trigger it");
    
  3. 你真的不应该做这些。如果用户复制 url 是不好的,那么你的应用程序设计就有缺陷。

  4. 编辑后添加:使用“空窗口”方法,但不是编写表单并触发它,而是XMLHTTPRequest在父级中执行(使用 POST)。此请求的结果可用于填充子窗口。

回答by HBublitz

Beside AJAX (jquery.load()), which I would use myself - how about the following approach:

除了 AJAX (jquery.load()),我自己会使用它 - 下面的方法怎么样:

<form method="post" action="edit.jsp" target="_blank">
      <input type="hidden" name="clientId" value="88"/>
      <input type="hidden" name="eventId" value="2"/>
</form>

target = _blank will actually open a new window /tab the posted data will be processed in. Unfortunatelly you can hardly control the new windows appearance.

target = _blank 实际上会打开一个新窗口 /tab 处理发布的数据。不幸的是,您几乎无法控制新窗口的外观。

回答by Shyju

How about implementing a model popup window using a div? You can make an http post call to load the content of that div/model popup. You can use jQuery load() method to load the content of the div as well.

如何使用 div 实现模型弹出窗口?您可以进行 http post 调用以加载该 div/model 弹出窗口的内容。您也可以使用 jQuery load() 方法来加载 div 的内容。

http://api.jquery.com/load/

http://api.jquery.com/load/

Some other model popup plugins are here

其他一些模型弹出插件在这里

http://jquery.com/demo/thickbox/

http://jquery.com/demo/thickbox/

http://colorpowered.com/colorbox/

http://colorpowered.com/colorbox/

http://fancybox.net/

http://fancybox.net/