Solved

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

Posted on 2006-10-20
3
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

628 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