最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to make a link placed inside an IFRAME open in the parent window - Stack Overflow

matteradmin7PV0评论

I have a JS game that's running inside an IFRAME, which is scaleable and all that fancy stuff.

The game contains a link to the next page, and the link works brilliantly.

Problems is that the link is opening inside the IFRAME and not the parent window. I need the flow to continue in the parent window and not the iframe.

the way the next page is linked in the IFRAME is like this:

LINK_BUTTON="data.php",

That's the only piece of code pointing out the link. To my regret I can't FIDDLE this because of disclosure issues.

Can anyone help me out?

I have a JS game that's running inside an IFRAME, which is scaleable and all that fancy stuff.

The game contains a link to the next page, and the link works brilliantly.

Problems is that the link is opening inside the IFRAME and not the parent window. I need the flow to continue in the parent window and not the iframe.

the way the next page is linked in the IFRAME is like this:

LINK_BUTTON="data.php",

That's the only piece of code pointing out the link. To my regret I can't FIDDLE this because of disclosure issues.

Can anyone help me out?

Share Improve this question edited May 28, 2015 at 10:41 Aurelio 25.9k9 gold badges61 silver badges64 bronze badges asked May 28, 2015 at 10:37 TjoerieTjoerie 251 silver badge9 bronze badges 2
  • Is LINK_BUTTON a javascript variable? – aldux Commented May 28, 2015 at 10:39
  • Yes it is. It's the first line next to the "var". – Tjoerie Commented May 28, 2015 at 10:39
Add a ment  | 

4 Answers 4

Reset to default 2

Use target="_parent" on your link.

<a target="_parent" href="data.php">link</a>

Or from Javascript

window.top.open("data.php");

Use the target attribute. This will force the link to open in the parent.

<a target="_parent" href="data.php">Next</a>

You can just set the target attribute. To open in the current top window (top frame):

<a href="http://example." target="_top">Link Text</a>

Or to open in a new window:

<a href="http://example." target="_blank">Link Text</a>

There's also _parent for the parent window (not necessarily the top) and _self for the current window (the default).

The short answer, as given above, is really to add target="_parent" attribute to your anchor (link).

The catch here is that you'll have to find in the javascript code where the LINK_BUTTON is used to generate the rendered link, and then in the code, add the target attribute.

Post a comment

comment list (0)

  1. No comments so far