JavaScript静态页面值传递之Window.open


现在PC配置越来越好,有些东西可以在前端做,并且也能够实现很好的性能。有些数据传递我们可以把它放到前端来操作(当然这些数据应该是无关安全性),所以今天我要在这分享关于前端页面值传递的方法之一···


这两窗口之间存在着关系.父窗口parent.htm打开子窗口son.htm
子窗口可以通过window.opener指向父窗口.这样可以访问父窗口的对象.
注:此案例请放在服务器环境测试.

parent.html

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head>
<title>parent页面</title>
</head>
<body>
<input type="text" name="maintext">
<input type="button" onclick="window.open('son.html');" value="Open">
</body>
</html>

son.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<title>son页面</title>
</head>
<body>
<script type="text/javascript">
var parentText = window.opener.document.all.maintext.value;
console.log(parentText);
</script>
</body>
</html>

优点:取值方便.只要window.opener指向父窗口,就可以访问所有对象.不仅可以访问值,还可以访问父窗口的方法.值长度无限制.
缺点:两窗口要存在着关系.就是利用window.open打开的窗口.不能跨域.

打赏

支付宝

支付宝

微信

微信

文章目录
收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
  • 评论
5人参与,5条评论
  • 最新评论
2019年10月20日 14:52 _ho5yBZ [辽宁省辽阳市网友]

该死的链家、简直就是无赖

来自tsrot spacewap版
2019年10月6日 8:27 不二心 [四川省内江市网友]

做任.务每天有钱,免费-拿iphone11-----米小邦(换成拼音).ㄈom

2019年9月11日 1:49 黄金相 [江苏省泰州市网友]

这家伙是不是有病。。

2019年9月6日 6:55 执子念 [辽宁省网友]

IOS试玩红包福.利,实测3天'120,秒到: shike.c 〇m/i/凵Qlzkew (凵大写.)

2019年7月25日 17:32 真的放不下你 [浙江省杭州市网友]

支`付`宝隐藏福`利,5折乘公`交,入口在首页`输:公交红包1316338