HTML5 two page delivery information

Source: Internet
Author: User

Use JS to pass information between pages on the server

Message Sending page index.html:

1 <!DOCTYPE HTML>2 <HTML>3 4     <Head>5         <MetaCharSet= "Utf-8" />6         <title></title>7     </Head>8 9     <Body>Ten         <inputtype= "text"name= "MSG"ID= "MSG"value="" /> One         <Buttononclick= "Send ()">Send</Button> A         <DivID= "Show"> -  -         </Div> the         <!-- -  -  - Description: Cross-document communication, corresponding unsafe +          - -         <Scripttype= "Text/javascript"> +             /*each time a new window is constructed, the message is sent only to the newly constructed form, possibly because the relationship is overwritten, and the old form does not have messages*/ A             varTargetwin; at             varSend= function() { -                 //var targetwin = new Window (' http://127.0.0.1:8020/PostMessage/demo.html '); -                 /*is still re-opened to reconstruct, passing information only to the new window*/ - Targetwin=window.open ('http://127.0.0.1:8020/PostMessage/demo.html', '_blank', 'width=400,height=300'); - Targetwin.onload= function() { - targetwin.postmessage (document.getElementById ('msg'). Value,'Http://127.0.0.1:8020/PostMessage'); in                 } -             } to Window.onmessage= function(event) { +                 if(Event.origin!= 'http://127.0.0.1:8020') { -                     return; the                 } *                 varShow=document.getElementById ('Show'); $ show.innerhtml+=(Event.origin+ 'The message came:' +Event.data+ '<br/>');Panax Notoginseng             } -         </Script> the  +     </Body> A  the </HTML>

Information Receive page demo.html

1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "UTF-8">5         <title></title>6     </Head>7     <Body>8         <Scripttype= "Text/javascript">9 Window.onmessage= function(Event)Ten             { One                 if(Event.origin!= 'http://127.0.0.1:8020'){ A                     return; -                 } - Document.body.innerHTML=(Event.origin+'The message came:'+event.data); the Event.source.postMessage ('callback message, here is'+ This. Location,event.origin); -             } -         </Script> -     </Body> + </HTML>

HTML5 two page delivery information

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.