如何用JavaScript获取当前页面的网址?

2024-11-07 17:53:08
推荐回答(2个)
回答1:

可以使用下列代码获取当前页面的网址:

window.location
// 或者
window.location.href

实例演示:

1、新建一个空白Html文档

2、输入javascript代码

3、查看效果

回答2:



thisDLoc = document.location;

thisURL = document.URL;

thisHREF = document.location.href;

thisSLoc = self.location.href;


thisTLoc = top.location.href;

thisPLoc = parent.document.location;

thisTHost = top.location.hostname;

thisHost = location.hostname;