tags:

views:

51

answers:

1

I am using jQuery and would like to display the images from my PC, rather than hosting them. I have the following:

/* works fine: */
.ui-widget-header .ui-icon {
  background-image: url(images/ui-icons_2e83ff_256x240.png);
} 

/* does not work: */
.ui-widget-header .ui-icon {
  background-image: url(file:///C:/ui-icons_2e83ff_256x240.png);
}

When I put file:///C:/ui-icons_2e83ff_256x240.png in a browser, it displays the actual image beautifully. Both locations are valid image locations.

Could this not working be to do with the image being a sprite? Does anyone have any ideas on this one? Many thanks.

+1  A: 

Not possible due to security.

The only way to load images with 'local' file paths is to request the page using it's local file path not the web server url. For example:

Instead of:

http://example.com/mypage.html

Use:

file:///C:/path/to/htdocs/mypage.html
zaf
That is strange. This works:.mystyle{ background-image: url(file:///C:/ui-icons_2e83ff_256x240.png); }and will output the following image when used in my own div.<div class="mystyle"></div>This is why I wondered if it was something special that jQuery uses when applying images?
Ben
Also, the file I am using is a local file.
Ben
Can you post your jquery code?
zaf
I have not altered the jQuery code, apart from where the images are being retrieved from. I am using the dialog library. It is just so strange how I can copy the file location into a browser and it works. The html file I am using is also a local file. So I just don't get why: .ui-widget-header .ui-icon {background-image: url(file:///C:/ui-icons_2e83ff_256x240.png)/*{iconsHeader}*/; } would not work. I appreciate this may be difficult to help me on, but after racking my brains for hours, I thought someone might be able to say "This is why". :) Thanks.
Ben
What you want to do works since I've tested it. Your problem is to do with your setup which only you have access to. It could be the forward/back slashes in your file path messing with windows or you are not escaping some characters in your javascript or the html/css is not valid/correct etc.
zaf
Thanks zaf. Could you post your css code that you tested to get the following to read from a local location? (Just the one line like below)ui-widget-header .ui-icon {background-image: url(file:///C:/ui-icons_2e83ff_256x240.png)
Ben
Note that I'm not using windows: .stretchedMargin{ background-image: url(file:///Users/zaf/etc/mages.gif); }
zaf
I can create my own styles and it works fine in the same page, it is the fact that I can't use file:/// in the jQuery styles for some strange reason. It isn't resolved, but I thank you for your help, I'll close this topic off now.
Ben