Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-20
3
Medium Priority
?
274 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:Mark Steggles
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 2000 total points
ID: 17773608
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

721 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