Javascript 如何在html中获取url,document.referer为空
请帮助获取调用此页面的当前URL?这有什么问题?becaz alert带有空警报Javascript 如何在html中获取url,document.referer为空,javascript,html,Javascript,Html,请帮助获取调用此页面的当前URL?这有什么问题?becaz alert带有空警报 <html> <head> <script> function check() { alert(document.referrer); } </script> </head> <body onload="check()"> </body> </html> 函数检查() { 警报(文件、参考文件); } 用这些方法
<html>
<head>
<script>
function check()
{
alert(document.referrer);
}
</script>
</head>
<body onload="check()">
</body>
</html>
函数检查()
{
警报(文件、参考文件);
}
用这些方法中的任何一种替换您的警报。它将起作用
alert(document.URL)
alert(window.location.href)
alert(document.location.href)
alert(window.location.pathname)
根据文件。推荐人
如果用户直接导航到页面(不是通过链接,而是通过书签),则该值为空字符串
如果要获取当前页面url,则可以使用
window.location.href
或者,如果您想访问特定的URL,请执行以下操作
function test(){
$(window.location).attr('href', '../your link');
};
要获取URL使用
var url = window.location.href;
获取什么URL?如果推荐人是空的,那是因为没有推荐人。你想达到什么目的?推荐人检查通常不是一项富有成效的任务,只是需要调用此页面的当前url。感谢您的所有答复。只是更新了问题。
var url = window.location.href;