0

I need to open this urls in a new tab. Right now they are opening in the same page.

var data = [ 
 {title: "1", url: "gallery1.html"}, 
 {title: "2", url: "gallery2.html"}, 
 {title: "3", url: "gallery2.html"}, 

My knowledge in javascript is very short. I tried things like:

<script type='text/javascript'> 
window.open(url); 
</script> 

or

.attr("xlink:href", function(d) { return d.example.url; }) 
.attr("xlink:target", "_blank") 
.attr("xlink:title", function(d) { return d.example.title; });
Script47
14.6k4 gold badges49 silver badges69 bronze badges
asked Aug 20, 2016 at 16:43

2 Answers 2

2
window.open(url, "_blank");

This will open it in a new page.

_blank is a special keyword that will tell .open to open in a new page.

Demo: https://jsfiddle.net/n780rz9o/

answered Aug 20, 2016 at 16:44
Sign up to request clarification or add additional context in comments.

6 Comments

@kajihood data.forEach(link => open(link.url, "_blank")) This will open all links in your array.
where I have to put that?
@kajihood Put it wherever you want to open a new page. If you have no programming experience I encourage you to do some readings on basic HTML5 apis.
Can you please put an example with my code? I tried to copy your demo and it says syntax error.
@kajihood Probably because I used ES6 syntax. Try converting it back to ES5 if you are using an older browser.
|
0

To loop trough your array do sth like this:

data.forEach(function(elem){
window.open(elem.url,"_blank");
});
answered Aug 20, 2016 at 16:46

2 Comments

Sorry, where do I have to put that? I'm trying to put it like this and it doesn't work
It just still doing the same

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.