• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Filename extract and insert in a src problem

Wrzl

New member
Sorry I cant speak German.

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:

<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
 
so, javascript´s "document.write" doesn´t like the "<script>" declaration. just try this...

Code:
<script language="JavaScript">
<!-- 
var fileName =location.pathname.substring(location.pathname.lastIndexOf('/')+1); 
document.write('<scr'); 
document.write('ipt src="http://www.abc.com/path/'+fileName+'.js"></scr'); 
document.write('ipt>'); 
//-->
</script>
 
Thanks for quick response.
This is gonna work.
But it results with:
page.html.js
Because its getting the filename with extension.
I tried it with this but it didnt work with html in it.
Is there any way to delete ".html" after getting file name ?
To use page.js
 
Hello Wrzl!

Try this code:

Code:
<script language="JavaScript">
<!-- 
var fileName =location.pathname.substring(location.pathname.lastIndexOf('/')+1,location.pathname.lastIndexOf('.'));
document.write('<scr'); 
document.write('ipt src="http://www.abc.com/path/'+fileName+'.js"></scr'); 
document.write('ipt>'); 
//-->
</script>
 
Zurück
Oben