rlr/dotjs-addon

Doc suggestion: How to target a path

bpierre opened this issue · 2 comments

Sometimes, you don’t want to target a whole domain, but only a path.

You could add this to the documentation:

How to target a specific path

CSS

You can use the @-moz-document Mozilla Extension:

/* Full path */
@-moz-document url-prefix(http://www.w3.org/Style/) {
  /* CSS here */
}

/* Regex */
@-moz-document regexp("^https?:\/\/www\.w3\.org\/Style\/.*") {
  /* CSS here */
}

Documentation: https://developer.mozilla.org/en/CSS/@-moz-document

JavaScript

You can test the window.location object:

// Search for a string
if (window.location.pathname.indexOf('/Style/') === 0) {
 // JS here
}

// Regex
if (/^\/Style\/.*/.test(window.location.pathname)) {
 // JS here
}

Documentation: https://developer.mozilla.org/en/DOM/window.location

rlr commented

I like!

rlr commented

Landed 7d003c0

Thanks!