Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 40cfc9e59e
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (24 sloc) 12.923 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><title>jQuery postMessage: Cross-domain scripting goodness</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad()"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>
<!-- Generated by Natural Docs, version 1.4 -->
<!-- http://www.naturaldocs.org -->
<!-- saved from url=(0026)http://www.naturaldocs.org -->
<div id=Content><div class="CFile"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="jQuery_postMessage:Cross-domain_scripting_goodness"></a>jQuery postMessage: Cross-domain scripting goodness</h1><div class=CBody><p><b>Version: 0.5, Last updated: 9/11/2009</b></p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>Project Home</td><td class=CDLDescription><a href="http://benalman.com/projects/jquery-postmessage-plugin/" class=LURL target=_top>http://benalman.com<wbr>/projects<wbr>/jquery-postmessage-plugin<wbr>/</a></td></tr><tr><td class=CDLEntry>GitHub</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-postmessage/" class=LURL target=_top>http://github.com/cowboy/jquery-postmessage/</a></td></tr><tr><td class=CDLEntry>Source</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-postmessage<wbr>/raw<wbr>/master<wbr>/jquery.ba-postmessage.js</a></td></tr><tr><td class=CDLEntry>(Minified)</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-postmessage<wbr>/raw<wbr>/master<wbr>/jquery.ba-postmessage.min.js</a> (0.9kb)</td></tr></table><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#jQuery_postMessage:Cross-domain_scripting_goodness" >jQuery postMessage: Cross-domain scripting goodness</a></td><td class=SDescription><b>Version: 0.5, Last updated: 9/11/2009</b></td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#License" >License</a></td><td class=SDescription>Copyright &copy; 2009 &ldquo;Cowboy&rdquo; Ben Alman, Dual licensed under the MIT and GPL licenses. </td></tr><tr class="SGeneric"><td class=SEntry><a href="#Examples" >Examples</a></td><td class=SDescription>This working example, complete with fully commented code, illustrates one way in which this plugin can be used.</td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#Support_and_Testing" >Support and Testing</a></td><td class=SDescription>Information about what version or versions of jQuery this plugin has been tested with and what browsers it has been tested in.</td></tr><tr class="SGeneric"><td class=SEntry><a href="#Release_History" >Release History</a></td><td class=SDescription></td></tr><tr class="SGroup"><td class=SEntry><a href="#Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent1 SMarked"><td class=SEntry><a href="#jQuery.postMessage" >jQuery.<wbr>postMessage</a></td><td class=SDescription>This method will call window.postMessage if available, setting the targetOrigin parameter to the base of the target_url parameter for maximum security in browsers that support it. </td></tr><tr class="SFunction SIndent1"><td class=SEntry><a href="#jQuery.receiveMessage" >jQuery.<wbr>receiveMessage</a></td><td class=SDescription>Register a single callback for either a window.postMessage call, if supported, or if unsupported, for any change in the current window location.hash. </td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="License"></a>License</h3><div class=CBody><p>Copyright &copy; 2009 &ldquo;Cowboy&rdquo; Ben Alman, Dual licensed under the MIT and GPL licenses.&nbsp; <a href="http://benalman.com/about/license/" class=LURL target=_top>http://benalman.com/about/license/</a></p></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Examples"></a>Examples</h3><div class=CBody><p>This working example, complete with fully commented code, illustrates one way in which this plugin can be used.</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>Iframe resizing</td><td class=CDLDescription><a href="http://benalman.com/code/projects/jquery-postmessage/examples/iframe/" class=LURL target=_top>http://benalman.com<wbr>/code<wbr>/projects<wbr>/jquery-postmessage<wbr>/examples<wbr>/iframe<wbr>/</a></td></tr></table></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Support_and_Testing"></a>Support and Testing</h3><div class=CBody><p>Information about what version or versions of jQuery this plugin has been tested with and what browsers it has been tested in.</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>jQuery Versions</td><td class=CDLDescription>1.3.2</td></tr><tr><td class=CDLEntry>Browsers Tested</td><td class=CDLDescription>Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.</td></tr></table></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Release_History"></a>Release History</h3><div class=CBody><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>0.5</td><td class=CDLDescription>(9/11/2009) Improved cache-busting</td></tr><tr><td class=CDLEntry>0.4</td><td class=CDLDescription>(8/25/2009) Initial release</td></tr></table></div></div></div>
<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="Functions"></a>Functions</h3></div></div>
<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="jQuery.postMessage"></a>jQuery.<wbr>postMessage</h3><div class=CBody><p>This method will call window.postMessage if available, setting the targetOrigin parameter to the base of the target_url parameter for maximum security in browsers that support it.&nbsp; If window.postMessage is not available, the target window&rsquo;s location.hash will be used to pass the message.&nbsp; If an object is passed as the message param, it will be serialized into a string using the jQuery.param method.</p><h4 class=CHeading>Usage</h4><blockquote><pre>jQuery.postMessage( message, target_url [, target ] );</pre></blockquote><h4 class=CHeading>Arguments</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>message</td><td class=CDLDescription>(String) A message to be passed to the other frame.</td></tr><tr><td class=CDLEntry>message</td><td class=CDLDescription>(Object) An object to be serialized into a params string, using the jQuery.param method.</td></tr><tr><td class=CDLEntry>target_url</td><td class=CDLDescription>(String) The URL of the other frame this window is attempting to communicate with.&nbsp; This must be the exact URL (including any query string) of the other window for this script to work in browsers that don&rsquo;t support window.postMessage.</td></tr><tr><td class=CDLEntry>target</td><td class=CDLDescription>(Object) A reference to the other frame this window is attempting to communicate with.&nbsp; If omitted, defaults to `parent`.</td></tr></table><h4 class=CHeading>Returns</h4><p>Nothing.</p></div></div></div>
<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="jQuery.receiveMessage"></a>jQuery.<wbr>receiveMessage</h3><div class=CBody><p>Register a single callback for either a window.postMessage call, if supported, or if unsupported, for any change in the current window location.hash.&nbsp; If window.postMessage is supported and source_origin is specified, the source window will be checked against this for maximum security.&nbsp; If window.postMessage is unsupported, a polling loop will be started to watch for changes to the location.hash.</p><p>Note that for simplicity&rsquo;s sake, only a single callback can be registered at one time.&nbsp; Passing no params will unbind this event (or stop the polling loop), and calling this method a second time with another callback will unbind the event (or stop the polling loop) first, before binding the new callback.</p><p>Also note that if window.postMessage is available, the optional source_origin param will be used to test the event.origin property.&nbsp; From the MDC window.postMessage docs: This string is the concatenation of the protocol and &ldquo;://&rdquo;, the host name if one exists, and &ldquo;:&rdquo; followed by a port number if a port is present and differs from the default port for the given protocol.&nbsp; Examples of typical origins are <a href="https://example.org" class=LURL target=_top>https://example.org</a> (implying port 443), <a href="http://example.net" class=LURL target=_top>http://example.net</a> (implying port 80), and <a href="http://example.com:8080" class=LURL target=_top>http://example.com:8080</a>.</p><h4 class=CHeading>Usage</h4><blockquote><pre>jQuery.receiveMessage( callback [, source_origin ] [, delay ] );</pre></blockquote><h4 class=CHeading>Arguments</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>callback</td><td class=CDLDescription>(Function) This callback will execute whenever a <a href="#jQuery.postMessage" class=LFunction id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">jQuery.postMessage</a> message is received, provided the source_origin matches.&nbsp; If callback is omitted, any existing receiveMessage event bind or polling loop will be canceled.</td></tr><tr><td class=CDLEntry>source_origin</td><td class=CDLDescription>(String) If window.postMessage is available and this value is not equal to the event.origin property, the callback will not be called.</td></tr><tr><td class=CDLEntry>source_origin</td><td class=CDLDescription>(Function) If window.postMessage is available and this function returns false when passed the event.origin property, the callback will not be called.</td></tr><tr><td class=CDLEntry>delay</td><td class=CDLDescription>(Number) An optional zero-or-greater delay in milliseconds at which the polling loop will execute (for browser that don&rsquo;t support window.postMessage).&nbsp; If omitted, defaults to 100.</td></tr></table><h4 class=CHeading>Returns</h4><p>Nothing!</p></div></div></div>
</div><!--Content-->
<div id=Footer><a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->
<div id=Menu><div class=MEntry><div class=MFile id=MSelected>jQuery postMessage: Cross-domain scripting goodness</div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Index</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MIndex><a href="../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Files.html">Files</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Functions.html">Functions</a></div></div></div></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option id=MSearchEverything selected value="General">Everything</option><option value="Files">Files</option><option value="Functions">Functions</option></select></div></div><!--Menu-->
<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CFunction>This method will call window.postMessage if available, setting the targetOrigin parameter to the base of the target_url parameter for maximum security in browsers that support it. </div></div><!--END_ND_TOOLTIPS-->
<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>
<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>
Jump to Line
Something went wrong with that request. Please try again.