对url的操作

url='http://localhost:3000/bulk_messages/edit?message_id=78'

(1) 获取url(带域名,带参数):
document.URL

结果:'http://localhost:3000/bulk_messages/edit?message_id=78'
window.location.href

结果同上

(2) 获取url(不包括域名,不带参数):
window.location.pathname

结果:‘/bulk_message/edit’

(3) 获取url的主机部分(带端口):
window.location.host

结果:‘localhost:3000’

(4) 获取url的主机部分(不带端口):
document.domain

结果:‘localhost’
location.hostname

结果同上

(5) 获取url中的参数:
window.location.search

结果: ‘?message_id=78’

(6) 获取url协议:
window.location.protocol

结果: ‘http:’

(7) 获取url端口部分:
window.location.port

结果: ‘3000’

你可能感兴趣的:(javascript)