วัตถุสถานที่ตั้ง
ตัวอย่าง
กลับ URL ทั้งหมด (ของหน้าปัจจุบัน):
var x = location.href;
ผลของ X จะเป็น:
ลองตัวเอง» เพิ่มเติม "ลองตัวเอง" ตัวอย่างด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติ href ชุดหรือส่งกลับ URL ทั้งหมดของหน้าปัจจุบัน
สนับสนุนเบราว์เซอร์
คุณสมบัติ | | | | | |
---|
href | ใช่ | ใช่ | ใช่ | ใช่ | ใช่ |
วากยสัมพันธ์
กลับคุณสมบัติ href:
ตั้งค่าคุณสมบัติ href:
ค่าทรัพย์สิน
Value |
Type |
Description |
URL |
String |
Specifies the URL of the link.
Possible values:
- An absolute URL - points to another web site (like location.href="http://www.example.com/default.htm")
- A relative URL - points to a file within a web site (like location.href="default.htm")
- An anchor URL - points to an anchor within a page (like location.href="#top")
- A new protocol - specifies a different protocol (like location.href="ftp://someftpserver.com",
location.href="mailto:[email protected]" or
location.href="file://host/path/example.txt")
|
รายละเอียดทางเทคนิค
กลับค่า: | สตริงที่เป็นตัวแทนของ URL ทั้งหมดของหน้ารวมทั้งโปรโตคอล (เช่น http: //) |
---|

ตัวอย่างเพิ่มเติม
ตัวอย่าง
กำหนดค่า href ให้ชี้ไปยังเว็บไซต์อื่น:
location.href = "http://www.cnn.com";
ลองตัวเอง» ตัวอย่าง
กำหนดค่า href ให้ชี้ไปที่ยึดเหนี่ยวภายในหน้า:
location.href = "#top";
ลองตัวเอง» ตัวอย่าง
กำหนดค่า href ให้ชี้ไปยังที่อยู่อีเมล (จะเปิดและสร้างข้อความอีเมลใหม่):
ลองตัวเอง»
วัตถุสถานที่ตั้ง