I have an html page and I would like inside the html page to retrieve the name of the html document via Javascript. Is that possible?
e.g. name of html document = "indexOLD.html"
var path = window.location.pathname; var page = path.split("/").pop(); console.log( page );
Current page: It's possible to do even shorter. This single line sound more elegant to find the current page's file name:
var fileName = location.href.split("/").slice(-1);
or...
var fileName = location.pathname.split("/").slice(-1)
This is cool to customize nav box's link, so the link toward the current is enlighten by a CSS class.
JS:
$('.menu a').each(function() { if ($(this).attr('href') == location.href.split("/").slice(-1)){ $(this).addClass('curent_page'); } });
CSS:
a.current_page { font-size: 2em; color: red; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With