The path of external JS and CSS files referenced in the master page

Source: Internet
Author: User
When the child pages of a nested master page are not in the same directory as the master page, the path referenced by external images, JS files, and CSS files is often involved. (The following describes how to reference others and organize them by yourself)
1. Images and <A> labels
Excellent solution
</SCRIPT>
<A href = "~ /Book/buy. aspx "mce_href = "~ /Book/buy. aspx "runat =" server "> </a>
With runat = "server" added, the PATH uses the absolute path ~ /It is basically OK.

2. CSS file reference
<LINK rel = "stylesheet" type = "text/CSS" href = "style.css" mce_href = "style.css"> </SCRIPT>
The magic here is that the href of The Link file is automatically adjusted with the directory structure of the accessed file. To put it bluntly, you can consider the path referenced by the master page.
For example, a master page cited by XXX. aspx in a folder under the same directory on the master page will automatically become
<LINK rel = "stylesheet" type = "text/CSS" href = "../style.css" mce_href = "style.css"> </SCRIPT>
The premise is that
3. js file reference
<MCE: Script Type = "text/JavaScript" src = "menu/jquery. Min. js" mce_src = "menu/jquery. Min. js"> </MCE: SCRIPT>
In this case, the client will not be able to reference the page files in other directories.
So you need to handle it like this
<MCE: Script Type = "text/JavaScript" src = '<% = resolveurl ("menu/jquery. Min. js") %> <! --
'>
// --> </MCE: SCRIPT>
<MCE: Script Type = "text/JavaScript" src = "<% = resolveclienturl (" mce_src = "& lt; % = resolveclienturl (" menu/jquery. min. JS ") %> <! --
'>
// --> </MCE: SCRIPT>

There are two methods, and the path on the client will be different, respectively:
<MCE: Script Type = "text/JavaScript" src = "/example/menu/jquery. min. JS "mce_src =" example/menu/jquery. min. JS "> </MCE: SCRIPT>
<MCE: Script Type = "text/JavaScript" src = "menu/jquery. Min. js" mce_src = "menu/jquery. Min. js"> </MCE: SCRIPT>
Obviously, resolveclienturl is a relative path, which is more useful. Of course, resolveurl also requires such an absolute path in many places. example is the name of the Web application.
In addition, if it is unavailable, add runat = "server" in the When a child page needs to reference its own CSS and JS external files, you can add a tag to the <Asp: contentplaceholder runat = "server" id = "headcontent">
</ASP: contentplaceholder>
Sub-pages can add files to be referenced in this tag
</ASP: Content
<Asp: Content ID = "content2" contentplaceholderid = "headcontent" runat = "server">
<LINK rel = "stylesheet" href = "CSS/thickbox.css" mce_href = "CSS/thickbox.css" type = "text/CSS"/>
<LINK rel = "stylesheet" href = "http://www.cnblogs.com/css/common.css" mce_href = "http://www.cnblogs.com/css/common.css" type = "text/CSS"/>
<MCE: Script Type = "text/JavaScript" src = "JS/jquery-1.4.1.min.js" mce_src = "JS/jquery-1.4.1.min.js"> </MCE: SCRIPT>
This article from: http://blog.csdn.net/liujun198773/archive/2010/09/29/5913882.aspx
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.