Forum Discussion
Quicklinks - open in a new tab
Hi inkaotto ,
I recently tried this myself with the Modern Script Editor. The thing that you could do to manipulate the standard behavior of links in the SharePoint environment is to target the id of the webpart and inject JavaScript to make the link target="_blank" and also make it so that data-interception="off".
Here is the code for implementing this:
<script>
document.querySelectorAll('[data-automation-id^="QuickLinksWebPart"] [role=listitem] a').forEach(function(anchor) {
anchor.setAttribute('target', '_blank');
anchor.setAttribute('data-interception', 'off');
});
document.querySelectorAll('[data-automation-id="CollapsibleLayer-Button"]').forEach(function(domClick) {
domClick.addEventListener("click", function() {
setTimeout(function() {
document.querySelectorAll('[data-automation-id^="QuickLinksWebPart"] [role=listitem] a').forEach(function(anchor) {
anchor.setAttribute('target', '_blank');
anchor.setAttribute('data-interception', 'off');
});
}, 500); // 0,5 second delay
});
});
</script>
The code above does two things. It first injects JavaScript on page load where all data-automation-id^="QuickLinksWebPart"] [role=listitem] are found. This would be enough if your page on SharePoint does not include sections. If you do not have any sections the only thing you would need is this:
document.querySelectorAll('[data-automation-id^="QuickLinksWebPart"] [role=listitem] a').forEach(function(anchor) {
anchor.setAttribute('target', '_blank');
anchor.setAttribute('data-interception', 'off');
});
But if you do have sections on your SharePoint page, then you need to add a delay to this injection of the script so that it waits for the user to click on the expand function for the section. When the user clicks that event the code that run on page load is overwritten.
Now you want your injection for the Quick Links to run after the script that opens the sections. Then you need to add a delay. I have added 0,5 seconds in this example:
document.querySelectorAll('[data-automation-id="CollapsibleLayer-Button"]').forEach(function(domClick) {
domClick.addEventListener("click", function() {
setTimeout(function() {
document.querySelectorAll('[data-automation-id^="QuickLinksWebPart"] [role=listitem] a').forEach(function(anchor) {
anchor.setAttribute('target', '_blank');
anchor.setAttribute('data-interception', 'off');
});
}, 500); // 0,5 second delay
});
});
I hope you find this helpful.
Best regards,
Oscar
I think Microsoft should provide a setting for each link in quick links web part to open the link in new tab, similar to how we can configure navigation links to open in a new tab in SharePoint.
There are already few feedback's submitted by other users - consider voting on them:
- Open in a new tab Quick Links WebPart SharePoint Online
- Allow Quicklinks to Open in a New Tab or Window
Meanwhile if you are unable to use the modern script editor web part or SPFx and/or custom scripting is not allowed in your company, you can right/second click on quick link and select Open link in new tab option like:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.