hwriter or reportingtools: open link in new tab?
2
0
Entering edit mode
Wade Davis ▴ 60
@wade-davis-7659
Last seen 6.9 years ago
USA

Does anyone have a solution using either hwriter or ReportingTools such that by default the links in the HTML open in a new tab or window when selected?

Looking at hwrite(), it seems that if the "target" attribute was available as optional argument, I could pass it the value "_blank" and that would do the trick.

Or is there something in the CSS or ReportingTools that could be modified to make this happen?

Thanks,

Wade

hyperlink ReportingTools hwriter • 1.6k views
ADD COMMENT
0
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 4.0 years ago
Heidelberg, Germany

Hi Wade,

the following JavaScript snippet does the trick of setting the target of external links to _blank.

document.addEventListener("DOMContentLoaded", function() {
  var links = document.links;  
  for (var i = 0, linksLength = links.length; i < linksLength; i++)
    if (links[i].hostname != window.location.hostname)
      links[i].target = '_blank';
});

This code is used in the BiocStyle package. The restriction to external links can be removed and the target of all links in the document modified by deleting the if clause.

Best,

Andrzej

ADD COMMENT
0
Entering edit mode
Wade Davis ▴ 60
@wade-davis-7659
Last seen 6.9 years ago
USA

Hi Andrzej,

Thank you for speedy reply; it worked like a charm.

Just to summarize for others using ReportingTools, what I did was add this snippet

document.addEventListener("DOMContentLoaded", function() {
  var links = document.links;  
  for (var i = 0, linksLength = links.length; i < linksLength; i++)
      links[i].target = '_blank';
});

to the /jslib/jquery.dataTables.reprise.js file used by ReportingTools.

 

Thanks again,

Wade

 

 

ADD COMMENT

Login before adding your answer.

Traffic: 723 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6