Skip to content

Commit

Permalink
Introducing self.origin, a reliable way to get the origin of a global
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk authored and domenic committed Apr 6, 2016
1 parent cdd48e1 commit 6bdba31
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -87543,6 +87543,8 @@ interface <dfn>DocumentAndElementEventHandlers</dfn> {

[NoInterfaceObject, Exposed=(Window,Worker)]
interface <dfn>WindowOrWorkerGlobalScope</dfn> {
[Replaceable] readonly attribute USVString <span data-x="dom-origin">origin</span>;

// base64 utility methods
DOMString <span data-x="dom-btoa">btoa</span>(DOMString data);
DOMString <span data-x="dom-atob">atob</span>(DOMString data);
Expand All @@ -87566,6 +87568,33 @@ interface <dfn>WindowOrWorkerGlobalScope</dfn> {
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1229
-->

<dl class="domintro">
<dt><var>origin</var> = self . <code subdfn data-x="dom-origin">origin</code></dt>

<dd><p>Returns the global object's <span>origin</span>, serialised as string.</p></dd>
</dl>

<div class="example">
<p>Developers are strongly encouraged to use <code data-x="">self.origin</code> over <code
data-x="">location.origin</code>. The former returns the <span>origin</span> of the environment,
the latter of the URL of the environment. Imagine the following script executing in a document on
<code data-x="">https://stargate.example/</code>:</p>

<pre>var frame = document.createElement("iframe")
frame.onload = function() {
var frameWin = frame.contentWindow
console.log(frameWin.location.origin) // "null"
console.log(frameWin.origin) // "https://stargate.example"
}
document.body.appendChild(frame)</pre>

<p><code data-x="">self.origin</code> is a more reliable security indicator.</p>
</div>

<p>The <dfn data-x="dom-origin"><code>origin</code></dfn> attribute's getter must return this
object's <span>relevant setting object</span>'s <span>origin</span>, <span data-x="Unicode
serialisation of an origin">serialised</span>.</p>


<h3 id="atob">Base64 utility methods</h3>

Expand Down

0 comments on commit 6bdba31

Please sign in to comment.