Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
a simple test for target=top links embedded in iframes, related to is…
Browse files Browse the repository at this point in the history
…sue #73
  • Loading branch information
lloyd committed Mar 28, 2011
1 parent febca4f commit 69d2cd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/target_top/index.html
@@ -0,0 +1,15 @@
<html>
<head>
<title>WebbyFox</title>

</head>
<body >
<p>
I'm the outer frame. you better not pwn me.
</p>

<iframe src="inner-page.html" width="400" height="100" border="2" >
</iframe>

</body>
</html>
9 changes: 9 additions & 0 deletions tests/target_top/inner-page.html
@@ -0,0 +1,9 @@
<html>
<head>
<title>WebbyFox</title>

</head>
<body>
<a href="inner-page.html" target="_top">Click here</a> I'm the inner frame. you've been pwned!
</body>
</html>

2 comments on commit 69d2cd4

@davidmurdoch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a highly-inefficient, error-prone, and messy hack for this:

                iframe.addEventListener("ChromelessDOMSetup", function () {
                    this.contentWindow.addEventListener("DOMContentLoaded", function () {
                        var as = this.document.getElementsByTagName("a");
                        for (var i = 0, l = as.length; i < l; i++) {
                            as[i].setAttribute("target", "_self");
                        }
                        var setTarget = function (e) {
                            e.target.setAttribute("target", "_self");
                        };
                        this.addEventListener("DOMNodeInserted", setTarget, false);
                        this.addEventListener("DOMAttrModified", setTarget, false);
                    }, false);
                }, false);

Appinfo.json needs the "enableSystemPrivileges" set to true.

@davidmurdoch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above snippet will probably break if you have a nested iframe with a target="_top" link.

Please sign in to comment.