請幫助獲取當前網頁的名稱?這是什麼問題?,becaz警報帶有空白。如何在html中獲取網址,document.referrer爲空
<html>
<head>
<script>
function check()
{
alert(document.referrer);
}
</script>
</head>
<body onload="check()">
</body>
</html>
請幫助獲取當前網頁的名稱?這是什麼問題?,becaz警報帶有空白。如何在html中獲取網址,document.referrer爲空
<html>
<head>
<script>
function check()
{
alert(document.referrer);
}
</script>
</head>
<body onload="check()">
</body>
</html>
根據MDNdocument.referrer
的值是空字符串,如果用戶導航到直接在頁面(未通過鏈路,但是,例如,通過書籤)。
你如果想獲得當前頁面的URL,那麼你可以使用
window.location.href
用這些方法中的任何一種替換您的提醒。它將工作。
alert(document.URL)
alert(window.location.href)
alert(document.location.href)
alert(window.location.pathname)
function test(){
alert(Window.location.href);
};
,或者如果你想要去的特定URL做到這一點
function test(){
$(window.location).attr('href', '../your link');
};
要獲得URL使用,
var url = window.location.href;
獲取什麼網址?如果引用者是空的,那是因爲沒有一個。 – Quentin
你想達到什麼目的?推薦人檢查通常不是一項富有成效的任務 – bobince
只需要調用此頁面的當前網址。 – sunleo