asp.net combined with html,javascript for non-flush cross-domain data submission

Source: Internet
Author: User
Tags flush html form in domain to domain

Demand:

A field has a page a.html, which has an IFRAME containing a B-field page b.html, now to pass the a.html on a button, to the A.html page in the text box to the text box to the b.html page.

Note: Here b.html is an HTML page, can not receive the value of other sites post, so you can not use the direct post method to pass the value, but, if the receiving page is b.aspx or b.asp, it is not a direct post it? The answer is yes, indeed, but b.asp or b.aspx must be refreshed, can, how can not refresh the dynamic change of the received page elements or values? (ie's local project is accessible across domains, but cross-domain access to the extranet is denied by default.) Both the Firefox local project and the Cross-domain access to the extranet are rejected. )

Principle:

The browser prohibits Cross-domain data access, but the browser does not prohibit post values across the frames across domains. We can implement data access in this domain by using a Frame page in Domain A, post to a page in the B field, and then through the frames pages of the B field. This is actually a small trick in HTML applications, and it does not use other advanced knowledge to achieve Cross-domain data submission.

Method:

Add two pages to domain B to enable Cross-domain data access, post.aspx and main.aspx.

Page relationships are as follows, the a.html of a field contains a frame, the frame page address is a B-field main.aspx,main.aspx is a frameset containing two frames, (frmmain) b.html and (Frmpost) post.aspx.

A.html of a domain:

<form action="http://www.b**.com/post.aspx" method="post" target="frmPost">
<input id="cmd" type="text" size="20">
<input type="submit">
</form>
<iframe src="http://www.b**.com/main.aspx"></iframe>

Main.aspx of B Domain:

<frameset rows="*,0" frameborder="no" border="0" framespacing="0">
<frame src="b.html" name="frmMain">
<frame src="post.aspx" name="frmPost">
</frameset>

We first save the data to the B-field into the A.html form and post it to the post.aspx in the B field.

The post.aspx receives the value and then executes the parent frame access b.html in this domain.

string cmd = Request.Form["cmd"];
if (null != cmd && string.Empty != cmd)
{
Response.Write("<script language=\"JavaScript\" for=\"window\" event=\"onload\"> if (parent && parent.frames[\"frmMain\"]) { 这里添加控制b.html的执行代码} </script> ");
}

It is not hard to find that the Cross-domain data access is achieved using a method of jumping across a frame (that is, the middle jumps over a frame). Post to the frame's child frame.

Postscript:

This example is just a special case of cross-domain access solutions that might help you. Because the method is simple, the application has many limitations. (But I think this is very much like Ajax Oh, the page did not refresh, also completed a server-side data processing ^o^).

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.