This repository was archived by the owner on May 7, 2025. It is now read-only.
This repository was archived by the owner on May 7, 2025. It is now read-only.
[question] How to block links inside an Epub #511
Open
Description
I use cloud reader lite to display an epub. Since there is no support for content tagged epub:type noteref, I made it myself (based on a script from epub.js) and I add it inside the epub content.
This works really fine on desktop, there is a small popover displayed on mouseover near the word to be defined. But on tablet, there is no onmouseover event, just the click event.
And when I click a link, the link is followed, whether it's an external link or an anchor.
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
{
if (links[i].getAttribute('epub:type') === 'noteref')
{
links[i].addEventListener("mouseover", showPop, false);
links[i].addEventListener("mouseout", hidePop, false);
links[i].addEventListener("click", disableClick, false);
}
}
function disableClick(e)
{
console.log('I was clicked');
e.preventDefault();
e.stopPropagation();
}
"I was clicked" is displayed but the preventDefault() does nothing, the click event is not stopped.
How can I prevent a link in the epub to open a new tab or to go the corresponding anchor ?