Framework element-Cross-origin access-location. hash, framework-location. hash
Page A: Page B. Can you pass data to me?
Page B: Well, we are not in the same domain. Because of WEB security problems, the browser prohibits me from directly uploading data to you.
Page A: Is there any way to solve this problem?
Page B: You can use location. hash.
Page A: What do you need me to do?
Page B: 1. Create an iframe node first. 2. Set the node attribute src to point to me. Do not forget to add the hash value! Wait, let's make an appointment. When the hash value you pass to me is # a, I add data B to your domain name with hash value # B, then you parse the URL and get data B.
Page A: OK. Thank you, PageB.
<! -- Page A --> <script> window. onload = function () {var ifr = document. createElement ('iframe'); ifr. style. display = 'none'; ifr. src = 'HTTP: // www. B .com/ B .html?a'{document.body.appendchild (ifr);} function getHash () {var data = location. hash? Location. hash. substring (1): ''; console. log ('data obtained from page B: '+ data);} setInterval (getHash, 2000); </script>
<! -- Page B --> <script> window. onload = function () {switch (location. hash) {case '# a': B () ;}} function setHash () {parent. location. hash = 'B' ;}</script>