惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - Shanks

Linux 内核中的 GCC 特性(zz) makefile strace工具 doxygen&make&智能指针 最近项目的一些技术问题 The ultimate jQuery Plugin List 关于html和javascript在浏览器中的加载顺序问题的讨论(zz) Yahoo!网站性能最佳体验的34条黄金守则——服务器(zz) 今日随笔(2008-08-27) Request-Line解释 下载了最新版本的live writer,在cnblogs上post一下试试 C++二维数组new小结(zz) rfc2616http协议笔记(1) 开始整理读书笔记 第一个Ajax小程序,了解Ajax原理 Atlas学习之一:学习轨迹及学习资料收集 OLAP和OLTP的区别(基础知识) XSLT分析之一:XPath表达式 JavaScript:QueryString(zz加解释)
js文件路径问题
Shanks · 2006-02-20 · via 博客园 - Shanks

做一个UserControl时候,不能用"../"指定相对路径,因为这将依赖于目录结构(只能固定某一层),也不能用"~",好象只有图片可以用这个,并且document.write也不能用"~"表示图片的根路径。我的解决办法是在页面load时候获取页面的href,然后处理后得到根路径,加上你的js存放路径就可以了。对于images或者css都可以这样处理。
var path=location.href;   
path=path.substring(0,path.lastIndexOf("/")+1);
path=path.substring(0,path.length-2);
path=path.substring(0,path.lastIndexOf("/")+1);   
jsDir=path+你js文件存放的路径;
document.write("<script language='javascript' src='" + jsDir+ "'></" + "script>"