最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url - relative path in javascript external file - Stack Overflow

programmeradmin4浏览0评论

I am trying to make this picture showing but I had no success.

If I do

$.blockUI.defaults.message = '<img src="../images/blockUI_Loader.gif" />';

I get from fiddler

If I do

$.blockUI.defaults.message = '<img src="../_assets/images/blockUI_Loader.gif" />';

I get from fiddler

If I use

$.blockUI.defaults.message = '<img src="~/_assets/images/blockUI_Loader.gif" />';

I get from fiddler

My folder structure is as follow

the js file is in the js folder.

I am trying to make this picture showing but I had no success.

If I do

$.blockUI.defaults.message = '<img src="../images/blockUI_Loader.gif" />';

I get from fiddler

If I do

$.blockUI.defaults.message = '<img src="../_assets/images/blockUI_Loader.gif" />';

I get from fiddler

If I use

$.blockUI.defaults.message = '<img src="~/_assets/images/blockUI_Loader.gif" />';

I get from fiddler

My folder structure is as follow

the js file is in the js folder.

Share Improve this question edited Nov 12, 2010 at 0:43 Lorenzo asked Nov 12, 2010 at 0:29 LorenzoLorenzo 29.4k50 gold badges128 silver badges224 bronze badges 1
  • Travis unfortunately did not accepted to be wrong...It deleted his answer and then came here to downvote...oh Travis Travis... – Lorenzo Commented Nov 12, 2010 at 1:38
Add a ment  | 

3 Answers 3

Reset to default 2

An alternative solution is to apply classes to your elements via JavaScript and set a background image using CSS.

Relative url paths in CSS are always relative to the stylesheet file which can make them easier to keep consistent.

For example

Javascript

$.blockUI.defaults.message = '<div class="blockUI-Loader"></div>';

CSS

.blockUI-Loader {
    /* url path is relative to this CSS file in "_assets/css" */
    background-image: url(../images/blockUI_Loader.gif);
    background-repeat: no-repeat;
    width: nnpx; /* width of image */
    height: nnpx; /* height of image */
}

The relative path is relative to the HTML file and not the js file. So looking above at your other files, I am guessing you need to images/...

Finally I have found the soultion!

$.blockUI.defaults.message = '<img src="_assets/images/blockUI_Loader.gif" />';
发布评论

评论列表(0)

  1. 暂无评论