开发者

Overcoming problems caused by creating subdirectories for js/css/xml files

I've been working on a website, using html,css,js and xml files on my computer (not online yet). I had an images folde开发者_C百科r, but otherwise was keeping all the files in the same folder. As the work progressed, things started to get somewhat messy, so I created css, js, and xml folders and carefully updated all my html, css, and js code. I immediately ran into the "Access to restricted URI denied code: 1012" error, discussed here, here, and here. Following the recommendation in the last link, I moved the site into my localhost server. This seems to have solved the 1012 error, but I still appear to be getting other errors (my js code seems to be having problems accessing html elements). Without being too specific, what are the problems and corresponding solutions relating to moving website files into subdirectories?


Problems associated with moving files into sub-folders.

  • Images included with CSS are relative to the location of the CSS file.
  • JavaScript references to other files are relative to the location of the page.

I've put together something to demonstrate

DEMO: http://wecodesign.com/demos/stackoverflow-7072742.htm


From my own personal experience, multiple folders always creates problems.

You can make modules out of your code and put all the public resources for each module inside the same folder group, but it's worth it only on really big projects (and we're talking Yahoo, Amazon, type scale here).

If it's so complicated, multiple folders are going to make things even more difficult. Keep your folder structure simple, and reduce the complexity of your code.


When moving style sheets to a css folder, just add ./css/ to the front of your hrefs in all your css links. Also add ../ the the front of all the image URLs in your css files. Moving javascripts to a js folder is similar, just add ./js/ to the front of your hrefs in all your js links. Moving .xmls to an xml folder can be more involved. Due to the 1012 error, you need to move you site to a server, if it isn't already on one. Then you need to go through your js code and add ./xml/ to the beginning of your xml references. If you've been good, you'll have a function called something like function openXMLfile(xmlFileName) and so you'll only need to change a single line: xmlhttp.open("GET", xmlFileName+".xml", false); to xmlhttp.open("GET", "./xml/"+xmlFileName+".xml", false); Thanks for other answers and comments. Helped. Upvoted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜