Welcome to WebmasterWorld Guest from 54.167.29.212

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Detect relative paths in a linked CSS stylesheet?

     

JAB Creations

1:08 am on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'm considering the option of allow people to add a URL to an external style sheet so they can adjust how my site appears when they visit. However if I did so I want to prevent those stylesheets from using relative paths to files such as background-images and cursors as some browsers do not correctly interpret relative paths. I would also require the absolute paths not to encase URLs in single or double quotes for backwards compatibility (my site tentatively supports IE on OSX for example). I essentially want to prevent 404s coming from other people by enforcing the rule via PHP.

So is it possible to access an external CSS file and determine if there are any relative paths based on the required rule that if a line contains the string "url" it must match "url(http://"?

- John

jatar_k

1:55 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



hmmm, you would have to open the remote file and then use regex to find every path in the file and then test them to make sure their pattern matches the pattern of an absolute url.

It seems like a lot of work, then what happens if they change the file?

Achernar

3:17 pm on Mar 28, 2008 (gmt 0)

5+ Year Member



Since the stylesheet is only applied to the user who has chosen to use it, why do you bother correcting _their_ errors?

JAB Creations

5:36 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Their errors translate in to more work for me if I have to wade through a pool of their 404s because they used relative paths considering it's cross-domain CSS.

Would this be a complicated regex? Would it be difficult to setup some sort of Apache anti-404 script that disallows images to load from my site if the referrer is a cross-domain CSS file? If that were possible I could skip the PHP script altogether possibly. I think off-hand at least.

- John

 

Featured Threads

Hot Threads This Week

Hot Threads This Month