Hey there,
for a site I was looking for a way to detect external links (for adding target=_blank, some SVG icon indicating external URLs etc) and came up with this approach:
# Check if URL is external
if (Url::stripPath(Url::to($url)) !== Url::stripPath(site()->url())) {
# Yep, external
$target = 'blank'; # or whatever
}
What are your approaches (like, using parse_url() or something)? Did you find this useful? Could my way be improved? (I guess so!)
a:not([href*="//"]) {
/* CSS for internal links */
}
a[href*="//"] {
/*CSS for external links */
}
Target blank is a controversial one - if had a choice (sometimes clients ask insist me to do it), I wont add this because it breaks the use of the back button which is bad for accessibility.
As Kirby isn’t working with relative links by default I had to come up with a slightly different rule specific to my URL and now it works, thanks a lot!
The css rule is a wild card partial string match and the // was just a starting point. I just did the relative / so that it wouldnt match the string. You have made it more specific by putting part of you domain name in there.