1

I have a webpart on a site that allows you to insert a "Show more" link to an external page that expands on the information displayed in the webpart. Unfortunately this option only takes a regular URL as the value for the link, it doesn't let you construct the HTML link itself. I need this link to open in a new tab but since I only get to put the URL in, I can't use the normal target="_blank" HTML code. Is there a way to craft the URL itself to force a new tab?

thanby
  • 323
  • 1
  • 6
  • 22

2 Answers2

4

In javascript:

   window.open("url");

Or adding the attr:

   document.getElementById("theLink").setAttribute("target", "_blank");

With the following html

   <a id="theLink" href="url">
Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69
1

If you cannot modify any part the a tag, you can use jquery.
The following script will try to open all links on a different tab/window:

$("a").on("click",function(){
       event.preventDefault();
       window.open($(this).attr('href'),'_blank');
});

NOTE:

Make sure you read this answer

Community
  • 1
  • 1
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268