Solved

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

Posted on 2006-10-20
3
249 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

746 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

12 Experts available now in Live!

Get 1:1 Help Now