Hi,

How do I make it so when I click a link on page A, it opens page B in a new window, and page A goes to a specified page?

This is the page:

I want to make it so when the user clicks view, the forums page goes back, and it opens the hyperlinked page in a new window, so the user is left with 1 window with the actual forum in, and another page with our homepage in.

Thanks,

Max

Dani AI

Generated

already solved this in post #2, but the snippet there is a bit messy and uses parent.parent. A cleaner, safer pattern is to let the anchor open the external page in a new tab/window and use JavaScript to navigate the current (or top) browsing context to your desired page. This keeps behavior predictable across browsers and avoids brittle frame-depth hacks.

Example (clean, modern):

<a href="https://external.example" target="_blank" rel="noopener noreferrer"
   onclick="top.location.href='https://your-homepage.example';">
  View
</a>
  • target="_blank" opens the linked page in a new tab/window.
  • rel="noopener noreferrer" is important for security (prevents the new tab from getting a window.opener reference).
  • onclick="top.location.href='...'" navigates the top-level window. If the link is not inside frames, use window.location.href instead. Avoid chaining parent.parent — prefer parent or top depending on the intended target, and test to confirm behavior.

For and : if the new tab does not appear, try the same markup without JavaScript (just target="_blank") to see whether pop-up blockers or JS errors are the issue. If the onclick navigation seems not to run, check the browser console for errors, ensure JavaScript is enabled, and do not return false from the handler (that would stop the normal link action). If your site uses nested frames or third-party frames, test across browsers — frame navigation behavior can be environment-dependent.

Further reading: MDN has concise guidance on the anchor element and rel="noopener" (MDN: <a> element) and on the top window object (MDN: Window.top).

Recommended Answers

All 5 Replies

don't worry, iv figured it out:

href="[URL]" target="_blank" onclick="parent.parent.location.href=''"

i didnt get what you mean to say..
can you lemme know maybe i will find it useful in future

i wanted a link that opened a new window on another page, and sent the first page back to the home page

So how did you do it?

he as answered it in 2nd post..
thanks a lot btw

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.