Currently, the hyperlinks always open a new window, which could leave the user with multiple windows for the same site, could you add a feature to select if a new window is opened? Most of the time I need the user to navigate to another part of the website.
Hi there, @Paul_Hayes1
Would you like to let your website visitors to choose how to open the links, or you want to have this setting in the configurator for yourself?
Hi, Max, I would like this option to choose if the link opens a new window or navigates to another page on the site, this feature is included in the FAQs widget for adding answers. A no-follow for links that open another website would also be useful. If a new browser window opens for each link on the blog page for the same site there will be too many browser tabs open for the same site.
Hi there, @Paul_Hayes1
Our devs came up with 2 solutions for your case.
The 1st code will open all links in the same tab:
const waitForElem = (selector) =>
new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(() => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
waitForElem('#__EAAPS_PORTAL[class*="eapps-blog"]').then((popup) => {
popup.addEventListener('click', (e) => {
const link = e.target.closest('a');
if (link?.href) {
e.preventDefault();
window.open(link.href, '_self');
}
});
});
And the 2nd code will open the links from the website where the widget is installed in the same tab. Links from other websites will be opened in a new tab:
const waitForElem = (selector) =>
new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(() => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
waitForElem('#__EAAPS_PORTAL[class*="eapps-blog"]').then((popup) => {
popup.addEventListener('click', (e) => {
const link = e.target.closest('a');
if (link && link.href.startsWith(window.location.origin)) {
e.preventDefault();
window.open(link.href, '_self');
}
});
});
Try it out and let us know if it worked for you
We agree that it would be great to have this feature right in the settings and I’ve added this idea to the Wishlist - Setting to open links in new/same tab
many thanks, will give it a try.