{"id":5724,"date":"2014-04-06T10:29:41","date_gmt":"2014-04-06T10:29:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/06\/javascript-to-detect-if-the-parent-frame-is-of-the-same-origin-collection-of-common-programming-errors\/"},"modified":"2014-04-06T10:29:41","modified_gmt":"2014-04-06T10:29:41","slug":"javascript-to-detect-if-the-parent-frame-is-of-the-same-origin-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/06\/javascript-to-detect-if-the-parent-frame-is-of-the-same-origin-collection-of-common-programming-errors\/","title":{"rendered":"JavaScript to detect if the parent frame is of the same origin?-Collection of common programming errors"},"content":{"rendered":"<p>I use this method to tell if an iframe contains local content,<\/p>\n<p>but you can pass it window.top from the iframe just as well<\/p>\n<pre><code>function islocal(win){\nvar H=location.href,\n    local= H.substring(0, H.indexOf(location.pathname));\n    try{\n        win=win.document;\n        return win &amp;&amp; win.URL &amp;&amp; win.URL.indexOf(local)== 0;\n    }\n    catch(er){\n        return false\n    }\n}\n<\/code><\/pre>\n<p>\/\/test case alert(islocal(window.top))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use this method to tell if an iframe contains local content, but you can pass it window.top from the iframe just as well function islocal(win){ var H=location.href, local= H.substring(0, H.indexOf(location.pathname)); try{ win=win.document; return win &amp;&amp; win.URL &amp;&amp; win.URL.indexOf(local)== 0; } catch(er){ return false } } \/\/test case alert(islocal(window.top))<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5724","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5724"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5724\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}