Rewrite relative URLs to absolute URLs via jQuery -
features:
- the site on different mirrors.
- javascript in external file, same mirrors.
- all external files in folder "assets".
- the ability launch site in local file system.
have code:
<link href="assets/css/example.css"> <script src="assets/js/example.js"></script>
result:
<link href="http://different.domain/assets/css/example.css"> <script src="http://different.domain/assets/js/example.js"></script>
you should check script tags have full url in src , not have src @ all. example:
$(function(){ var domain = window.location.protocol + '//' + window.location.host + '/'; $('script').each(function(){ var src = $(this).attr('src'); if( 'undefined' !== typeof src && '' != src && !src.match(/^https?:/) ){ $(this).attr('src', domain + src); } }); });
Comments
Post a Comment