SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript trouble accessing cross-domain CSS file

    http://page-test.co.uk/js.php

    The above link shows my attempt to read a CSS file hosted on a CDN.

    Why won't it work and what can I do?

    I have access to all and everything, so can change anything.

    I have tried to implement CORS, but no luck.

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnsmith153 View Post
    http://page-test.co.uk/js.php

    The above link shows my attempt to read a CSS file hosted on a CDN.

    Why won't it work and what can I do?

    I have access to all and everything, so can change anything.

    I have tried to implement CORS, but no luck.
    I've just tried a few things and did some research and it seems that this is something purposefully implemented do avoid XSS type attacks. (In fact, the issue that it was allowed was lodged as a bug in Webkit and fixed a few years ago https://bugs.webkit.org/show_bug.cgi?id=20527 - they were modelling this behaviour after Firefox who'd already implemented it.)

    Is there any particular reason you need to access the style rules in an external stylesheet? (And if it's important to do so, why not host the CSS file yourself?)

    If you need to know the styles associated with a particular element you can always use:
    Code JavaScript:
    window.getComputedStyle( ele ).getPropertyValue( propVal ); //where ele is a DOM element propVal is a CSS property
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •