簡體   English   中英

如何在控制台登錄您在 JavaScript 中查看的文件的名稱?

[英]How do I log in the console the name of the file you are viewing in JavaScript?

我想在控制台登錄頁面的名稱。

假設您在 index.html 上,然后在控制台中會顯示“index.html”

使用window.location.pathname獲取路徑名,然后通過/ s 分割找到當前頁面並獲取最后一項。

 console.log("Full URL: " + location); console.log("Current Page: " + window.location.pathname.split("/").pop());

一個快速的谷歌搜索給了我這個答案:

var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/')+1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM