user3418870
user3418870

Reputation:

Unable to open popup when clicking on a node with URL in d3.js

In one of my project I'm using D3.js to make tree. Some of the child nodes links to various places.I'm trying to open a popup window when a user clicks on a node, that has URL. The part of the code that I'm trying is:

e.append("svg:a").attr("target", "E2B").attr("xlink:href", function(a) {
  return a.url;
}).append("text").attr("x", function(a) {
  return a.children || a._children ? -10 : 10;
}).attr("dy", ".35em").attr("text-anchor", function(a) {
  return a.children || a._children ? "end" : "start";
}).text(function(a) {
  return a.name;
}).style("fill-opacity", 1E-6)
  .on("click",window.open(d.url,'','width=600,height=300'));

Using the above code, when I load the project in my browser, I receive a new blank pop-up window on load. Additionally, when I click on one of the child node, that contains URL, the same blank pop-up window opens. Can someone please tell me what is wrong with my code?

In case you need, here's my entire HTML code - http://pastebin.com/tLZfmEg9

Upvotes: 0

Views: 1067

Answers (1)

user3418870
user3418870

Reputation:

Here's the working code that I solved my self. Replace the code given in the question with this one.

e.append("svg:a").attr("target", "E2B").on("click", function(a){
if( a.url == null){} else {
  window.open(a.url,'',"width=800,height=600")}
}).append("text").attr("x", function(a) {
  return a.children || a._children ? -10 : 10;
}).attr("dy", ".35em").attr("text-anchor", function(a) {
  return a.children || a._children ? "end" : "start";
}).text(function(a) {
  return a.name;
}).style("fill-opacity", 1E-6);

Upvotes: 1

Related Questions