0

我想确定 Javascript 中页面的 URL。这可能吗?我怎样才能做到这一点?非常感谢你

4

3 回答 3

4

window.location对象

根据您是否需要哈希、查询字符串等,有许多不同的属性可用。

例如,在此页面上;

window.location.hash: "#11537761";
window.location.host: "stackoverflow.com";
window.location.hostname: "stackoverflow.com";
window.location.href: "http://stackoverflow.com/questions/11537718/how-to-determine-the-page-url-at-run-time-in-javascript/11537761#11537761";
window.location.origin: "http://stackoverflow.com";
window.location.pathname: "/questions/11537718/how-to-determine-the-page-url-at-run-time-in-javascript/11537761";
于 2012-07-18T09:00:06.687 回答
1

快速谷歌:

<SCRIPT LANGUAGE="JavaScript">
  alert(location.href);
</SCRIPT>
于 2012-07-18T08:59:45.330 回答
1

在 JavaScript 中你有document.URL

alert(document.URL);
于 2012-07-18T09:00:03.707 回答