I have a Chrome extension that has some links in it. Currently when clicked the links do nothing, i would like to make them open in a new tab when clicked. Is this possible?
Add target="_blank"
to links.
Another way is to attach link opening javascript code to mousedown event on a link.
You can also use base
tag to make all links open with target="_blank"
:
<head>
<base target="_blank">
</head>
I had the same issue and this was my approach:
<script src="popup.js" ></script>
Add the following code to popup.js:
document.addEventListener('DOMContentLoaded', function () {
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
(function () {
var ln = links[i];
var location = ln.href;
ln.onclick = function () {
chrome.tabs.create({active: true, url: location});
};
})();
}
});
That's all, links should work after that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With