How to use DOM to create link element that opens in new window

Posted on 2006-10-20
Last Modified: 2013-11-19

I do this to dynamically create a link element:

var lk=document.createElement("a");
lk.appendChild(document.createTextNode('Example file'));

However the link opens in the same window. I want it to open in a new window. I know that you can use target="_blank" in HTML. But how do I do it in JS/DOM?

Question by:tr5
LVL 30

Expert Comment

ID: 17773017
Greetings tr5,

To open a new window with javascript you can use the method, see


Author Comment

ID: 17773424
Steggs - thanks for replying
I need to do it using DOM functions only. See my code example.
LVL 23

Accepted Solution

rama_krishna580 earned 500 total points
ID: 17773608

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to install NodejS to run a JavaScript application 3 31
how can display objects ? 3 33
how can i remove string values 2 29
how can i check if the text is an Isogram ? 2 24
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now