Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update local link detection to account for relative links (e.g. css/screen.css) #5

Merged
merged 2 commits into from

2 participants

@Nentuaby

Current isLocalUrl produces a false negative for relative urls such as 'css/default.css'.

The solution I used is to employ the javascript property .href instead of getting the value of the 'href' attribute. The javascript property (according to my testing in Firefox, Opera, Chrome, and IE9) returns a fully qualified URL no matter the value of the href attribute, sidestepping the problem.

@philc philc merged commit c768238 into from
@philc
Collaborator

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2011
  1. @Nentuaby
  2. @Nentuaby

    Simplified code a bit

    Nentuaby authored
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +6 −3 livecss.js
View
9 livecss.js
@@ -33,7 +33,7 @@ var livecss = {
var media = (linkElements[i].getAttribute("media") || "").toLowerCase();
if (linkElements[i].getAttribute("rel") == "stylesheet"
&& livecss.indexOf(validMediaTypes, media) >= 0
- && this.isLocalUrl(linkElements[i].getAttribute("href"))) {
+ && this.isLocalLink(linkElements[i])) {
this.refreshLinkElement(linkElements[i]);
}
}
@@ -133,8 +133,11 @@ var livecss = {
return false;
},
- /* returns true for local urls such as: '/screen.css', 'http://mydomain.com/screen.css' */
- isLocalUrl: function(url) {
+ /* returns true for local urls such as: '/screen.css', 'http://mydomain.com/screen.css', 'css/screen.css'
+ */
+ isLocalLink: function(linkElement) {
+ //On all tested browsers, this javascript property returns a normalized URL
+ var url = linkElement.href;
var regexp = new RegExp("^\/|^" +
document.location.protocol + "//" + document.location.host);
return (url.search(regexp) == 0);
Something went wrong with that request. Please try again.