Science, Tech, Math › Computer Science Target a Window or Frame Using JavaScript or HTML Use top.location.href and other link targets in Java Share Flipboard Email Print Adam Gault/OJO Images/Getty Images Computer Science Javascript Programming PHP Programming Perl Python Java Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Stephen Chapman Stephen Chapman Computer Science Expert B.S., Computer Science, North Carolina State University Stephen Chapman is a Senior Oracle PL/SQL Developer at SEI Financial Services, with over 20 years' experience in software development and consulting. Learn about our Editorial Process Updated on February 21, 2020 Windows and frames are terms used to describe what may appear when you click a link in a website. Without extra coding, links will open in the same window you're currently using, meaning you'll need to press the back button to return to the page you had been browsing. But if the link is defined to open in a new window, it will appear in a new window or tab on your browser. If the link is defined to open in a new frame, it will pop up on top of the current page in your browser. With an ordinary HTML link using the anchor tag, you can target the page the link refers to in a way that the link, when clicked, will display in another window or frame. Of course, the same can also be done from within Javascript — in fact, there's plenty of overlap between HTML and Java. Generally speaking, you can use Java to target most types of links. Using top.location.href and Other Link Targets in Java Code in either HTML or JavaScript to target links so that they open either in new blank windows, in parent frames, in frames within the current page, or in a specific frame within a frameset. For example, to target the top of the current page and break out of any frameset currently in use you would use <a href="page.htm" target="_top"> in HTML. In Javascript you use top.location.href = 'page.htm'; which achieves the same objective. Other Java coding follows a similar pattern: Link Effect HTML JavaScript Target a new blank window <a href="page.htm" target="_blank"> window.open("_blank"); Target top of the page <a href="page.htm" target="_top"> top.location.href = 'page.htm'; Target current page or frame <a href="page.htm" target="_self"> self.location.href = 'page.htm'; Target parent frame <a href="page.htm" target="_parent"> parent.location.href = 'page.htm'; Target a specific frame within a frameset <a href="page.htm" target="thatframe"> top.frames['thatframe'].location.href = 'page.htm'; Target a specific iframe within current page <a href="page.htm" target="thatframe"> self.frames['thatframe'].location.href = 'page.htm'; When you target a specific frame within a frameset or a specific iframe within the current page, replace "thatframe" shown in the code with the name of the frame where you want the content to be displayed. However, keep the quotation marks — they're necessary. When you're using JavaScript coding for links, pair it with an action, such as onClick, or onMousover. This language will define when the link should be opened. Cite this Article Format mla apa chicago Your Citation Chapman, Stephen. "Target a Window or Frame Using JavaScript or HTML." ThoughtCo, Aug. 25, 2020, thoughtco.com/target-a-window-or-frame-using-javascript-or-html-4092194. Chapman, Stephen. (2020, August 25). Target a Window or Frame Using JavaScript or HTML. Retrieved from https://www.thoughtco.com/target-a-window-or-frame-using-javascript-or-html-4092194 Chapman, Stephen. "Target a Window or Frame Using JavaScript or HTML." ThoughtCo. https://www.thoughtco.com/target-a-window-or-frame-using-javascript-or-html-4092194 (accessed June 11, 2023). copy citation By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookies Settings Accept All Cookies