Forum Moderators: open
<script language="JavaScript"><!--
var fileName =location.pathname.substring(location.pathname.lastIndexOf('/')+1);
document.write('<script src="http://www.abc.com/path/'+fileName+'.js"><\/script>');
//--></script>
What is the correct syntax?
Thanks
Thirdly, get rid of the HTML comments (I heard somewhere that some browsers don't like them): <!-- and //-->
HTH
You could try escaping all the slashes and the < in your strings:
var fileName = location.pathname.substring(location.pathname.lastIndexOf('\/')+1);
document.write('\074script src=\042http:\/\/www.abc.com\/path\/' + fileName + '.js\042>\074\/script>');
That should ensure the code will validate if it's an embedded script.
There's no actual syntax error that I can find. Perhaps you could describe what actually happens and what error message you are getting.