如何使用JS或JQuery检测URL是否有端口ID

How to detect if the URL has port ID or not using JS or JQuery?

本文关键字:是否 ID URL 检测 何使用 JS JQuery      更新时间:2024-02-04

如果这是最好的代码?

if(window.location.origin.split(":")[1] > 4) {
    return false;
}else {
    return true;
}

您想要location.portlocation对象的一部分)。

return !!location.port; // true if there is a port, false otherwise