andreaskoch / allmark

A cross-platform markdown web server
https://allmark.io
Other
314 stars 73 forks source link

force open new tab in new window #32

Closed sprite2200 closed 4 years ago

sprite2200 commented 4 years ago

HI there, I know that we could always use example to force a hyperlink to open in new tab.

But the case I have already wrote like hundreds of them, is it possible there is a switch somewhere to do this? Thanks! btw, like this repo so much!

sprite2200 commented 4 years ago

I added a external.js as follows: function externalLinks() { for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) { var b = c[a]; b.getAttribute("href") && b.hostname !== location.hostname && (b.target = "_blank") } } ; externalLinks();

save it in /theme/external.js and call it in the main go

refer to: https://html.com/attributes/a-target/#:~:text=You%20don't%20need%20to,links%20into%20_blank%20links%20automatically.