Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check port number in url string?

Tags:

javascript

Can I check whether the port number is existing in a given URL string or not?

Like sometimes a user can type 202.567.89.254:8088 or http://202.567.89.254:8088/ or http://202.567.89.254.

Out of all the above options, if the port number is existing, then do nothing otherwise append 8080 by default with an end slash 8080/.

Is it possible in JavaScript?

like image 473
Sumit Aggarwal Avatar asked May 30 '16 07:05

Sumit Aggarwal


People also ask

What is port name in URL?

Use in URLs Port numbers are sometimes seen in web or other uniform resource locators (URLs). By default, HTTP uses port 80 and HTTPS uses port 443, but a URL like http://www.example.com:8080/path/ specifies that the web browser connects instead to port 8080 of the HTTP server.

How do I find the protocol of a URL?

The getProtocol() function is a part of URL class. The function getProtocol() returns the Protocol of a specified URL.

What is port number of https?

The SCI protocol uses only HTTPS to secure for the credentials passed in each request. By default, these two protocols are on their standard port number of 80 for HTTP and 443 for HTTPS.


1 Answers

You can try to use the location object and use:

location.port

The HTMLHyperlinkElementUtils.port property is a USVString containing the port number of the URL.

like image 62
Rahul Tripathi Avatar answered Nov 10 '22 03:11

Rahul Tripathi