Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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

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
tr5
Asked:
tr5
1 Solution
 
Mark StegglesWeb DeveloperCommented:
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
 
tr5Author Commented:
Steggs - thanks for replying
I need to do it using DOM functions only. See my code example.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now