search
HomeWeb Front-endJS Tutorialwindow.open() implements post passing parameters_javascript skills

In actual projects, we often encounter the need to jump between subsystem pages and open them in a new page. My project team uses the SSH framework, so the URLs are similar to **** .action, and also has two parameters (system ID and system name). The two parameters are intercepted by struts and stored in the session. In the opened subsystem page, there is also a tree menu implemented by the ztree plug-in that requires the parameter system ID. To initialize, using window.open(url, "_blank") directly will make the url length too long and expose some parameters. Therefore, I want to use the post method to submit, hiding the transfer of parameters during the submission process. First of all, I think of ajax submission, but there will be problems with the transfer of the two parameters. Ajax submission and window.open() will make the action go through twice, so they are discarded. Then I took a closer look at the window.open() API, link address http://www.w3school.com.cn/jsref/met_win_open.asp. window.open() defaults to the get submission method. If you want to implement the post submission method, you have to think of another way. Refer to http://www.jb51.net/article/32826.htm, here is a method. It is also a commonly used method. I modified it slightly according to the actual situation:

Copy code The code is as follows:

function openPostWindow(url, name, data1, data2){
var tempForm = document.createElement("form");
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
tempForm.target=name;
var hideInput1 = document.createElement("input");
​ hideInput1.type = "hidden";
​ hideInput1.name="xtid";
hideInput1.value = data1;
var hideInput2 = document.createElement("input");
​ hideInput2.type = "hidden";
​ hideInput2.name="xtmc";
hideInput2.value = data2;
tempForm.appendChild(hideInput1);
tempForm.appendChild(hideInput2);
If(document.all){
         tempForm.attachEvent("onsubmit",function(){});                                                                                                 }else{
          var subObj = tempForm.addEventListener("submit",function(){},false);         //firefox
}
​ document.body.appendChild(tempForm);
If(document.all){
         tempForm.fireEvent("onsubmit");
}else{
         tempForm.dispatchEvent(new Event("submit"));
}
tempForm.submit();
Document.body.removeChild(tempForm);
}
//function openWindow(name){
// window.open("",name);
//}

The number of parameters in the openPostWindow() function can be modified according to actual needs. data1 and data2 are the parameters that need to be passed to the action. In addition, Javascript event browser compatibility issues need to be considered here. I commented the function openWindow() here, otherwise an extra blank page (about:blank) will be opened. This basically meets the needs.

The above is all the content shared in this article, I hope you all like it.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
浅析php中POST方法带参数跳转页面浅析php中POST方法带参数跳转页面Mar 23, 2023 am 09:15 AM

对于PHP开发者来说,使用POST带参数跳转页面是一项基本技能。POST是HTTP中一种发送数据的方法,它可以通过HTTP请求向服务器提交数据,跳转页面则是在服务器端进行页面的处理和跳转。在实际开发中,我们经常需要使用POST带参数来跳转页面,以达到一定的功能目的。

python requests post如何使用python requests post如何使用Apr 29, 2023 pm 04:52 PM

python模拟浏览器发送post请求importrequests格式request.postrequest.post(url,data,json,kwargs)#post请求格式request.get(url,params,kwargs)#对比get请求发送post请求传参分为表单(x-www-form-urlencoded)json(application/json)data参数支持字典格式和字符串格式,字典格式用json.dumps()方法把data转换为合法的json格式字符串次方法需要

php怎么判断post有没有提交php怎么判断post有没有提交Mar 21, 2023 pm 07:12 PM

PHP是一种广泛使用的服务器端脚本语言,它可以用于创建交互式和动态的Web应用程序。在开发PHP应用时,我们通常需要通过表单将用户输入数据提交给服务器端处理。然而,有时候我们需要在PHP中判断是否有表单数据被提交,这篇文章将介绍如何进行这样的判断。

window.open如何关闭打开的窗口window.open如何关闭打开的窗口Dec 06, 2023 pm 02:15 PM

关闭打开的窗口的方法:1、使用“window.close”关闭新窗口;2、使用“window.location”重定向;3、使用“window.blur”和“window.focus”;4、使用“window.history”回退;5、使用“window.opener”。

java如何发起http请求调用post与get接口java如何发起http请求调用post与get接口May 16, 2023 pm 07:53 PM

一、java调用post接口1、使用URLConnection或者HttpURLConnectionjava自带的,无需下载其他jar包URLConnection方式调用,如果接口响应码被服务端修改则无法接收到返回报文,只能当响应码正确时才能接收到返回publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

机器学习超参数调优总结(PySpark ML)机器学习超参数调优总结(PySpark ML)Apr 08, 2023 pm 07:21 PM

ML中的一个重要任务是模型选择,或者使用数据为给定任务找到最佳的模型或参数。这也称为调优。可以对单个的估计器(如LogisticRegression​)进行调优,也可以对包括多种算法、特性化和其他步骤的整个pipeline​进行调优。用户可以一次调优整个Pipeline​,而不是分别调优 Pipeline 中的每个元素。ML中的一个重要任务是模型选择,或者使用数据为给定任务找到最佳的模型或参数。这也称为调优。可以对单个的Estimator​(如LogisticRegression​)进行调优,也

NGINX反向代理对HTML页面的POST请求返回405怎么解决NGINX反向代理对HTML页面的POST请求返回405怎么解决May 22, 2023 pm 07:49 PM

实现如下:server{listen80;listen443ssl;server_namenirvana.test-a.gogen;ssl_certificate/etc/nginx/ssl/nirvana.test-a.gogen.crt;ssl_certificate_key/etc/nginx/ssl/nirvana.test-a.gogen.key;proxy_connect_timeout600;proxy_read_timeout600;proxy_send_timeout600;c

100亿参数的语言模型跑不动?MIT华人博士提出SmoothQuant量化,内存需求直降一半,速度提升1.56倍!100亿参数的语言模型跑不动?MIT华人博士提出SmoothQuant量化,内存需求直降一半,速度提升1.56倍!Apr 13, 2023 am 09:31 AM

大型语言模型(LLM)虽然性能强劲,但动辄几百上千亿的参数量,对计算设备还是内存的需求量之大,都不是一般公司能承受得住的。量化(Quantization)是常见的压缩操作,通过降低模型权重的精度(如32bit降为8bit),牺牲一部分模型的性能来换取更快的推理速度,更少的内存需求。但对于超过1000亿参数量的LLM来说,现有的压缩方法都无法保持模型的准确率,也无法在硬件上高效地运行。最近,麻省理工学院和英伟达的研究人员联合提出了一个通用后训练的量化(GPQ, general-purpose po

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function