2012-07-18 80 views

回答

4

window.location object

取決於你是否想要散列,查詢字符串等有很多不同的屬性可用。

例如,在這個頁面上;

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: "https://stackoverflow.com/questions/11537718/how-to-determine-the-page-url-at-run-time-in-javascript/11537761"; 
+0

謝謝大家!這是我正在尋找的答案 – user1517150 2012-07-27 15:26:34

1

快速谷歌:

<SCRIPT LANGUAGE="JavaScript"> 
    alert(location.href); 
</SCRIPT> 
相關問題