簡體   English   中英

如何使用jQuery從URL獲取端口號?

[英]How to get the port number from the URL using jQuery?

這是URL:

http:// localhost:8888/index.html. 

如何使用jQuery從此URL獲取端口號?

它在location對象中可用:

location.port

請注意,如果URL中沒有端口,則location.port將返回一個空字符串。

如果即使使用隱式默認端口也需要獲取端口,請嘗試:

var port = location.port || (location.protocol === 'https:' ? '443' : '80');

這足以滿足通過httphttps協議提供的頁面的需求。

您不需要jQuery。

window.document.location.port

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM