跨域访问方法介绍(3)--使用片段识别符传值
片段标识符(fragment identifier)指的是,URL 中 # 号后面的部分,比如 的 #fragment。如果只是改变片段标识符,页面不会重新刷新。父窗口可以把信息,写入子窗口的片段标识符。子窗口通过监听 hashchange
事件得到通知;同样的,子窗口也可以改变父窗口的片段标识符。本文主要介绍使用片段标识符来实现跨域数据传递,文中所使用到的软件版本:Chrome 90.0.4430.212。
1、步骤说明
在 a.html 页面嵌入 b.html 页面,然后 a.html 改变 b.html 的片段标识符,b.html 接受到消息后改变父页面的片段标识符。
2、a.html ><!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>片段识别符 测试</title></head><body> <iframe src="http://localhost:9090/b.html" id="frame"></iframe> 父页面 <button onclick="sendMessage()">向子页面传数据</button></body><script type="text/javascript"> function sendMessage() { let src = document.getElementById('frame').src; document.getElementById('frame').src = src + "#hello"; } window.onhashchange = function() { alert(window.location.hash); } </script></html>
3、b.html ><!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>子页面</title><script type="text/javascript"> window.onhashchange = function() { alert(window.location.hash); parent.location.href = ""; }</script></head><body> 子页面</body></html>
4、测试
4、测试
把 a.html 放到 tomcat (端口:8080) 的 webapps\ROOT 下,b.html 放到另一个 tomcat (端口:9090) 的 webapps\ROOT 下。
原文转载:http://www.shaoqun.com/a/814646.html
车公车掀起裙子强行进 车子颠一次就进入的更深:http://lady.shaoqun.com/m/a/247945.html
趁女朋友洗澡上她闺蜜 把女闺蜜摸出水了:http://lady.shaoqun.com/m/a/247548.html
坐腿上写作业顶弄满满 写错一题顶弄一下:http://lady.shaoqun.com/m/a/247807.html
环球b2b:https://www.ikjzd.com/w/1762
片段标识符(fragmentidentifier)指的是,URL中#号后面的部分,比如的#fragment。如果只是改变片段标识符,页面不会重新刷新。父窗口可以把信息,写入子窗口的片段标识符。子窗口通过监听hashchange事件得到通知;同样的,子窗口也可以改变父窗口的片段标识符。本文主要介绍使用片段标识符来实现跨域数据传递,文中所使用到的软件版本:Chrome90.0.4430.212。1、步
亚马逊黄金日购物意愿降低?电子商务整体搜索量下降84%:https://www.ikjzd.com/articles/132109
也门人奇葩奇俗 就爱嚼树叶度日(全文):http://www.30bags.com/a/416061.html
心理调频:女人如何度过爱的空窗期:http://lady.shaoqun.com/m/a/10489.html
口述实录:睡觉之前男女干这事竟会短命:http://lady.shaoqun.com/m/a/251737.html
口述:我和小姨子那些旧事儿(上)(11/12):http://lady.shaoqun.com/m/a/85049.html
口述被三人干了一晚上 两个男人做我的详细过程:http://lady.shaoqun.com/m/a/248079.html
虚构:每次老婆出差,总是说家里有人,直到老婆出差,半夜有人摸我:http://www.30bags.com/a/442879.html
2020 Wish年度卖家云峰会,人、货、运的全面升级!:https://www.ikjzd.com/articles/132153
史上最前沿的测评养号系统,亚马逊测评如何降低成本,提高效率,搭建稳定的IP环境?:https://www.ikjzd.com/articles/132151
同桌偷偷伸进来揉我胸 被男同桌强开解胸罩吃奶:http://lady.shaoqun.com/a/247782.html
华南大学女生的故事和我冷战时期的恋情:http://www.30bags.com/a/442877.html
民间传说:县令夫人出轨撞墙,加入奸夫顶替花木:http://www.30bags.com/a/442878.html
Plaas 'n opmerking for "跨域访问方法介绍(3)--使用片段识别符传值 "