Frame, iframe pass or modify data method across domains

Source: Internet
Author: User

The example of this article, using the frameset, frame split form, the following code is a typical Web site background mode, the top of the Bannner bar, the following split between the two parts, of course, you can use JavaScript combined with table tags and so on to achieve the same function.

The code is as follows Copy Code

<frameset>
<frame name= "banner" src= "banner.php" >
<frameset cols= "150,*" >
<frame name= "left" target= "right" src= "left.php" >
<frame name= "Right" src= "right.php" >
</frameset>
<noframes>
<body>
<p> does not support framework </p>
</body>
</noframes>
</frameset>

I. Assigning values to a frame across domains
Through top and using getElementsByTagName to implement cross frame submission data, the following methods are:

For example, the right.php content is as follows, modifying the values in the banner document through JavaScript.

The code is as follows Copy Code

<script type= "Text/javascript" >
Try{window.top.banner.document.getelementsbytagname (' div ') [0].innerhtml= ' I am the title ';}
catch (e) {}
</script>

Two, cross-domain modify the form and so on elements
you can use a JS script like this:

The code is as follows Copy Code
1 var obj=parent.otherframename.document.forms[0].xxx;

To get the form control object, and then assign the value.


Submit data across frame by get method
Modify the SRC attribute of the frame, and then pass the value that needs to be passed through the Get method. However, the data receiver is required to add the appropriate receive processing script. Through the Get method can generally achieve some simple data transfer, if you want to implement dynamic cross frame modify page elements or some complex, as the above method is simpler.

The code is as follows Copy Code

<script type= "Text/javascript" >
Try{window.top.banner.src= ' banner.php?title= me is the title ';}
catch (e) {}
</script>

Passing data across domains using cookies or sessions
Set the cookie value or session value through a domain, and then dynamically refresh the page across the domain through the JS script, read the cookie or session again to achieve the purpose of passing data, but if the frame source address is a third party address, use cookies, may be invalidated because of browser blocking. It also seems to be possible to avoid the effect by sending a P3P header, but it has not been validated for the time being.

Data transmission of embedded frame IFRAME
IFrame is relatively simple to pass data, after all, in the same document, directly using parent to get the parent container, the code is as follows.

The code is as follows Copy Code

<div id= "abc" >
<div id= "Content" >http://www.111cn.net</div>
<iframe id= "iframe1" src= "test.html" ></iframe>
</div>
Test.html
<script type= "Text/javascript" >
function Change () {
Parent.document.getElementById ("Content"). InnerHTML = "Tian Yuan blog";
}
</script>
<input type= "button" id= "Buttion1" onclick= "Change ();" >

Passing cookies across domains in an IFRAME

Speak directly to the solution.

PHP's Program

Can be written directly in the B Web site

The code is as follows Copy Code
<?php
Header (' p3p:cp= "cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR" ")
?>

So you can accept a third party cookie.

Server for LIGHTTPD

The code is as follows Copy Code

Server.modules = ("Mod_setenv")

Setenv.add-response-header = ("P3P" => "cp= ' cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI D SP COR ' ")

Apache Server

The code is as follows Copy Code

<VirtualHost>

Header set P3P ' cp= ' cura ADMa DEVa Psao psdo our bus UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR "'

</VirtualHost>

Server for IIS
Add a website HTTP header to solve the problem;
admin tools--〉 Select a Web site--〉 attribute--〉http header, add an HTTP header
Then enter the header names: P3P
Input header content: Cp=cao PSA Our

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.