Solved

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

Posted on 2006-10-20
3
255 Views
Last Modified: 2013-11-19
Hi

I do this to dynamically create a link element:

var lk=document.createElement("a");
lk.href='files/example.doc';
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?

Thanks
tr5
0
Comment
Question by:tr5
3 Comments
 
LVL 30

Expert Comment

by:Steggs
ID: 17773017
Greetings tr5,

To open a new window with javascript you can use the window.open() method, see http://www.javascripter.net/faq/openinga.htm

Regards
0
 

Author Comment

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

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 17773608
0

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