jquery file_exists


/ Published in: jQuery
Save to your folder(s)

do you want to check a file exists using jQuery ?
that's is useful for none server side support servers or static projects
or for multi-themes website
هذا الكود يفيدك في التحقق من وجود ملف على السيرفر بدون الحاجة للتعامل مع لغة خادم
مفيدة جداً للمواقع العادية والتي تستخدم أكثر من ثيم في الموقع


Copy this code and paste it in your HTML
  1. // url like : http://yoursite.com/hello
  2. // url like : http://yoursite.com/second
  3.  
  4. var pathArray = window.location.pathname.split('/');
  5. $.ajax({
  6. url: "/css/my_style_"+pathArray[1].toLowerCase()+".css",
  7. type:'HEAD',
  8. error: function()
  9. {
  10.  
  11. $("#colorCss").attr("href","/css/my_style.css");
  12. },
  13. success: function()
  14. {
  15. $("#colorCss").attr("href","/css/my_style_"+pathArray[1].toLowerCase()+".css");
  16. }
  17. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.