Ahmed
Ahmed

Reputation: 160

Add diffrenet href to some nodes in cytoscape.js

I set href for some nodes and it works fine but the other nodes opening blank page Is it possible make them without href and don´t open blank page?

I used this to make href :

cy.nodes('[id = "start"]').data('href', 'https://js.cytoscape.org/');

cy.on('tap', 'node', function() {
  try {
    window.open(this.data('href'));
  } catch (e) {
    window.location.href = this.data('href');
  }
});

Upvotes: 0

Views: 96

Answers (1)

Ravenous
Ravenous

Reputation: 1160

Yes, listen for events that come from node[href], this means nodes that have href within their data set.

cy.on('tap', 'node[href]', function() {})

I'm not totally sure about this, but it should work. If not, just add

if (!this.data('href')) return;

As the first line in your handler.

Upvotes: 2

Related Questions