Hostname of URL in JavaScript

Asked 2 years ago, Updated 2 years ago, 97 views

In JavaScript, for example, the URL is document.location.href = "http://aaa.bbb.ccc.com/asdf/asdf/sadf.aspx?blah" if you say

aaa.bbb.ccc.com I just want to bring this part, what should I do?

javascript hostname

2022-09-21 19:27

1 Answers

Let me give you an example. http://sub.domain.com/page.htmIf you have a URL like this

If you do window.location.host, You will receive a sub.domain.com:8080 or sub.domain.com:80 value.

If you do window.location.hostname, You will receive sub.domain.com.

If you do window.location.protocol, you receive http: and

If you do window.location.port, you will receive 8080 or 80.

If you do window.location.origin, you will receive http://sub.domain.com *.


2022-09-21 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.