Open related item in new tab/window
Posted: 25 Oct 2016
Is it possible to have links in the related items control open in a new tab or window when clicked?
Design SharePoint forms with tabs, complex tables, accordions, sub-lists, and 3rd party columns
https://spform.com/forum/
Code: Select all
EditLink2 = function(item,i){
window.open($(item).attr('href'), '_blank');
};
Never managed to get this to work. Am I missing something? Does it make a difference that im displaying the form in a Modal Popup? Im trying to make related documents open in a new tab, instead of taking the user away from the form each time.YuriyMedvedev wrote: ↑26 Oct 2016Hi! Just put this code in Javascript:
Code: Select all
EditLink2 = function(item,i){ window.open($(item).attr('href'), '_blank'); };
Code: Select all
//Add related-items class to the Related Items control first
$('.related-items #idHomePageNewItem').removeProp('onclick');
$(".related-items #idHomePageNewItem").on("click", function(event){
event.preventDefault();
var item = $(".related-items #idHomePageNewItem");
window.open(item.attr('href'), '_blank');
});
Code: Select all
$('.related-docs .ms-listlink').removeProp('onclick');
$(".related-docs .ms-listlink").on("click", function(event){
event.preventDefault();
var item = $(".related-docs .ms-listlink");
window.open(item.attr('href'), '_blank');
});
Thank you Nikita, that works great!Nikita Kurguzov wrote: ↑02 Aug 2017Try using this code:Replace related-docs with the class of your Related Documents control first though.Code: Select all
$('.related-docs .ms-listlink').removeProp('onclick'); $(".related-docs .ms-listlink").on("click", function(event){ event.preventDefault(); var item = $(".related-docs .ms-listlink"); window.open(item.attr('href'), '_blank'); });
Code: Select all
function openInNewTab() {
$('.related-docs .ms-listlink').removeProp('onclick');
$(".related-docs .ms-listlink").on("click", function(event){
event.preventDefault();
var item = $(".related-items .ms-listlink");
window.open(item.attr('href'), '_blank');
});
$(".related-docs .ms-commandLink").on("click", function(event){
openInNewTab();
});
}
openInNewTab();
That seems to break the code? It opens a new blank window?Nikita Kurguzov wrote: ↑02 Aug 2017Indeed, when there are multiple pages of documents, switching between pages overrides this code.
Try this instead:Though, I do advice caution. There might be some issues with this code if you have some documents which are only for download and cannot be opened online.Code: Select all
function openInNewTab() { $('.related-docs .ms-listlink').removeProp('onclick'); $(".related-docs .ms-listlink").on("click", function(event){ event.preventDefault(); var item = $(".related-items .ms-listlink"); window.open(item.attr('href'), '_blank'); }); $(".related-docs .ms-commandLink").on("click", function(event){ openInNewTab(); }); } openInNewTab();
Code: Select all
var myVar = setInterval(myTimer, 100);
function myTimer() {
$('.related-items .ms-listlink').removeProp('onclick');
$(".related-items .ms-listlink").on("click", function(event){
event.preventDefault();
var item = $(this);
window.open(item.attr('href'), '_blank');
});
}