Home Comments Thread
New Thread

7 Comments

giscus-bot giscus-bot 2022-12-17 03:59:14
Guest *Daijiang Li* @ 2018-09-21 14:29:05 originally posted:

Great to learn this trick.

For blogdown users with Hugo as their websites' engines, it is possible to set hrefTargetBlank to true. An example here: https://github.com/rbind/daijiang/blob/master/config.yaml#L118

@daijiang

yihui yihui 2022-12-17 03:59:20

Thanks! This method has two limitations: 1. It only works with the Markdown renderer Blackfriday (e.g. on Hugo websites); 2. It adds target="_blank" to all links in the body of the post. The JS solution I provided is a general-purpose solution that works on all links on any HTML pages.

Originally posted on 2018-09-22 02:27:37

giscus-bot giscus-bot 2022-12-17 03:59:15
Guest *Lorraine Lee* @ 2018-10-27 19:05:40 originally posted:

I suppose, like many in my age cohort (older generation X) I was a very early adopter of the Internet and later the Web and tend to have "old school" attitudes about many of these things.

I think of web pages in general as possessing two cosmetically similar (sometimes identical) things that serve different functions. One is links ( elements). The other is text spans styled the same as links, whose destinations are onclick handlers rather than URL's. I'm actually overjoyed that someone wishes to use this concept for good rather than shady.

But still, I'm old enough to remember that the original idea behind CSS was that styling should be the prerogative of the audience, not the developers. If it were as simple as one of my browser settings is a master CSS template to go over every page I visit, mine would be something like a {color:purple; background:mauve; text-decoration: triple-overline-with-spots} and I'd happily assume anything in purple text over mauve background that's triple overlined with spots is a link and that anything that looks like a link is probably one of those Javascript tricks that someone is using to monetize a website.

As for the blank target thing, I only ever follow links by clicking right mouse button, then select "open link in new tab". It's a grooved reflex with me, largely grooved by the stuff described elsewhere in the present comment. Nothing like pain to train the brain. Other grooved reflex is ALWAYS hovering any link/pseudolink (as the case may be) before (even left) clicking. But Facebook et al even spoof the title attribute to ≠ the href.

giscus-bot giscus-bot 2022-12-17 03:59:16
Guest *Yongfu Liao* @ 2019-08-08 13:23:55 originally posted:

Cool!

Just came up with an idea to further improve user experience:

Add a css style that targets external links,
so that user knows whether it opens a new tab before clicking the links.

a[href^="http"]::after{  
content: "⧉";  
}  
yihui yihui 2022-12-17 03:59:21

Clever idea! I did this in JavaScript for the rmarkdown website: https://github.com/rstudio/rmarkdown/blob/dc278e4753b27991e9878f1d60b0c32f9a2ffa0d/js/external-links.js#L9

Originally posted on 2019-08-08 14:06:03

IdoBar IdoBar 2025-01-28 05:36:52

Thanks for this suggestion, but I couldn't understand where to put this code in an Rmarkdown file for it to change all my links.

giscus-bot giscus-bot 2022-12-17 03:59:17
Guest *Xiaorui (Jeremy) Zhu* @ 2019-08-28 01:58:02 originally posted:

This is helpful

giscus-bot giscus-bot 2022-12-17 03:59:18
Guest *Andrea Borruso* @ 2020-05-06 09:12:00 originally posted:

thank you

giscus-bot giscus-bot 2022-12-17 03:59:18
Guest *Simon Woodward* @ 2020-07-16 20:36:26 originally posted:

This great! I added this js to my shiny app and it was working well. But something has changed and it no longer works (no error, just doesn't open in new tab). Any reason this might be?
tabPanel(
title = "Help", icon = icon("question-circle"),
tags$div(
id = "help",
includeScript(path = "www/open_in_new_tab.js"),
withMathJax(includeMarkdown(file.path("www/explorer_help.md")))
)
)

giscus-bot giscus-bot 2022-12-17 03:59:19
Guest *Alexis W* @ 2020-11-03 16:23:47 originally posted:

For note 1, it's usually pretty easy on mobile devices too: just long press a link, it should open a contextual menu with the full link (nice to know where you might end up without actually going), and options for opening in a new tab etc. I use that all the time on Firefox on Android, but I would expect other browsers/OS would have an equivalent.

On computers, the middle click (or three fingers click on a touchpad) also opens in a new tab without opening the contextual menu.

Sign in to join the discussion

Sign in with GitHub