前言

我使用的场景是,点击弹窗,然后把我当前用户的消息传过去

获取当前用户信息

打开Chrome浏览器,在application那里可以看到cookie的其实

通过Cookie获取当前用户的姓名和邮箱

        var ca = document.cookie.split(';');
var name = '';
var email = '';
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf('name') == 0) {
accountContactName = c.substring(19, c.length);
} else if (c.indexOf('email') == 0) {
accountName = c.substring(12, c.length);
}
}

使用window.open的两种方式

Get方式

这种方式很简单,但是不推荐使用,为什么呢?因为你的参数全部都显示在了url里面,信息暴露了

window.open("http://test.com/controller/Index?name=" + name + "&email=" + email ,"", "width=810,height=630,top=100,left=200")

Post方式

这种方式好用,先写两个js方法

    function openPostWindow(url, username, useremail, name) {  //url要跳转到的页面,data要传递的数据,name显示方式(可能任意命名)
var tempForm = $("<form>");
tempForm.attr("id", "tempForm1");
tempForm.attr("style", "display:none");
tempForm.attr("target", name);
tempForm.attr("method", "post");
tempForm.attr("action", url);
var input1 = $("<input>");
input1.attr("type", "hidden");
input1.attr("name", "username");
input1.attr("value", username);
var input2 = $("<input>");
input2.attr("type", "hidden");
input2.attr("name", "useremail");
input2.attr("value", useremail);
tempForm.append(input1);
tempForm.append(input2);
tempForm.on("submit", function () { openWindow(name); }); // 必须用name不能只用url,否则无法传值到新页面
tempForm.trigger("submit");
$("body").append(tempForm);//将表单放置在web中
tempForm.submit();
$("tempForm1").remove();
}; function openWindow(name) {
window.open('about:blank', name, "width=810,height=630,top=100,left=200,toolbar=no, menubar=no, scrollbars=yes,resizable=yes,location=no, status=no");
};

然后调用的时候这样调用

openPostWindow('http://test.com/controller/Index', name, email,"随便起的名字");

window.open post传参的更多相关文章

  1. window.location.href 传参中文乱码问题!!!

    不是所有地方都会用Ajax  当你使用window.location.href 来传中文参数的时候 如何避免乱码问题 js 是这样写的    下面代码中  方式 封装编码  参数 username  ...

  2. 点击div 跳转并通过URL传参

    点击div前要先给div绑定要传的参数: //给panel绑定自定义属性,方便在跳转时传带参数,键/值对排列 panel.attr("user_age",user_age); pa ...

  3. 纯html页面之间传参

    //页面引入//传参方法,可解析url参数 (function($){ $.getUrlParam = function(name) { var reg = new RegExp("(^|& ...

  4. url传参中文乱码

    当使用url重定向传参的时候,比如: javascript:window.location.href='modifyBook.jsp?BName=<%=URLEncoder.encode(&qu ...

  5. JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参

    <script src="jquery.min.js" type="text/javascript"></script> <scr ...

  6. (转)Javascript匿名函数的写法、传参、递归

    (原)http://www.veryhuo.com/a/view/37529.html (转)javascript匿名函数的写法.传参和递归 javascript匿名函数的写法.传参和递归 http: ...

  7. (转)javascript匿名函数的写法、传参和递归

    (原)http://www.veryhuo.com/a/view/37529.html (转)javascript匿名函数的写法.传参和递归 http://www.veryhuo.com 2011-0 ...

  8. js实现页面a向页面b传参的方法

    方法一:使用HTML5本地化存储(localStorage) 组件(本地最大能存储5M数据)localStorage是本地永久存储数据,是cookie的优化 方法二:使用cookie将数据存放在客户的 ...

  9. echarts html传参+js请求+ashx服务 代码方式

    html 头传参方式 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <hea ...

随机推荐

  1. Logstash 安装配置使用

    一.Windows下安装运行 官网下载,下载与elasticSearch同一个版本,zip格式.Logstash占用内存较大,我在使用的时候cpu一般都是冲到90% 1.CMD直接运行 创建一个基本的 ...

  2. 1-STM32物联网开发WIFI+GPRS(Wi-Fi入门篇)_简介

    这期的教程为公开教程将用这块开发板学习WIFI(SDK) 实现哪些功能呢!无非就是那写网络功能...但是涉及的挺多 最近一直在忙方案篇的内容,所以公开版的例程耽误了,现在开始补上 我准备改变一下提供资 ...

  3. PHP 源码安装常用配置参数和说明

    常用的配置参数1. --prefix=/usr/local/php指定 php 安装目录install architecture-independent files in PREFIX 默认/usr/ ...

  4. c语言实现杨辉三角形

    #include <stdio.h> int main(void) { int a[9][9]={}; int i,j; for(i=0;i<9;i++){ for(j=0;j< ...

  5. noi.ac #42 模拟

    \(des\) 二维平面上存在 \(m\) 个点,每个点会对该点的 \(8\) 个方向上的最近的点产生影响 问每个点会被影响多少次 \(sol\) 过每个点会产生 \(4\) 条线段 保存每条线段的斜 ...

  6. 通过 frp 实现群晖的 drive 远端同步

    通过 frp 实现 drive 同步 其实其他的也类似, 只是指定 tcp 的端口不一致就可以. frp 实现的外网端口映射"肥肠"方便. 也推广下 frp 的地址 frp-git ...

  7. jenkins之SSH Publishers环境变量

    我使用的是docker部署jenkins,使用172.16.1.245作为部署服务器. 1.问题 在SSH Publishers里执行的环境变量,不是ssh server主机设置的环境变量,这样会导致 ...

  8. 11.linux dns服务器建立和安装apache

    dns服务器建立 1.安装bind建立dns服务器     yum install bind -y 2.安装好修改配置文件:vim /etc/named.conf 修改:      listen-on ...

  9. ubuntu之路——day9.2 Covariate shift问题和Batch Norm的解决方案

    Batch Norm的意义:Covariate shift的问题 在传统的机器学习中,我们通常会认为source domain和target domain的分布是一致的,也就是说,训练数据和测试数据是 ...

  10. 登录注册页面模板汇总WEB前端(50套)

    土地指标管理系统入口登录页面 土地指标管理系统入口登录页面.zip: https://u18740809.pipipan.com/fs/18740809-382374353 紫色响应式登录页面模板 紫 ...