Framework element-Cross-origin access-location. hash, framework-location. hash

Source: Internet
Author: User

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>

  

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.