| Welcome to WebmasterWorld Guest from 22.214.171.124 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
This script extracts html name and give it to a src with a js file in an other domain.
There is a syntax problem in this script which I couldnt find:
var fileName =location.pathname.substring(location.pathname.lastIndexOf('/')+1);
What is the correct syntax?
Firstly, doesn't location.pathname have back-slashes instead of forward-slashes? Try lastIndexOf('\')+1
Secondly, when it works, I think you'll get the following URL in your src attribute (note the unwanted ".htm"):
Thirdly, get rid of the HTML comments (I heard somewhere that some browsers don't like them): <!-- and //-->
Pathnames on the WWW are UNIX-based, so they do use forward slashes.
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.
Thanks for your help guys.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved