mohsen1 / json-formatter

Angular directive for collapsible JSON in HTML
http://azimi.me/json-formatter/demo/demo.html
Other
372 stars 85 forks source link

make an option to make links open in a new window #54

Open thatkookooguy opened 8 years ago

thatkookooguy commented 8 years ago

Currently, when clicking on urls (inside the compiled json), it triggers a navigation.

Can you please add an option to open urls in a new window? or maybe make that the default behavior?

mohsen1 commented 8 years ago

JSON Formatter core lib allows you to interact with the element. You can intercept clicks on links and fore it to open in a new window:

const formatter = new JSONFormatter({a:'http://github.com'});
const element = formatter.render();
element.addEventListener('click', event=> {
  if (event.target.href) {
     event.target.setAttribute('target', '_blank');
  }
});
document.body.appendChild(element);

For your custom behavior you can use the core lib with above API to achieve what you are looking for.

thatkookooguy commented 8 years ago

thx a lot for the quick help!

love the library btw :-)