If you don’t go into details, why do I need this, then the task is the following: regardless of whether the site is on the local or remote server, save the name of the current file to the variable value without permission.
Here is the code:
var fileName = location.href.split("/").slice(-1);
// Value at this stage checked - displays, for example, "info.php"
if (fileName == "#" || fileName == "") {var fileName="index";} // Если страница - начальная else{ //alert(fileName); // позиция 1 fileName = fileName.replace(/\.php$/i,''); alert(fileName); // позиция 2 }
If we are not on the main page (index.php), then we get into else
. I made sure that it works through alert (fileName); in position 1 . However, in position 2 , it no longer works, i.e. there is no window at all. No error messages.
Such code:
fileName="info.php"; fileName=fileName.replace(/\.php$/i,''); // 1 в 1 с предыдущим кодом alert(fileName);
I checked on jsfiddle; everything works there.
What can be wrong?