Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use assign and protocol in location

Shulou Source: shulou.com Published: 2022-06-01 03:29:38 10月01日 Update

This article mainly explains "how to use assign and protocol in location". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use assign and protocol in location.

How to use assign,protocol in location

_ window.location.protocol returns the web protocol used (http: or https:)

_ window.location.assign loads a new document

Window Location protocol

The _ window.location.protocol property returns the web protocol of the page.

Example

Displays the web protocol:

Document.getElementById ("demo"). InnerHTML = "Page Protocol is" + _ window.location.protocol

The result is:

The page protocol is http:

Window Location port

The _ window.location.port property returns the number of the Internet host port (of the current page).

Example

Displays the port number of the host:

Document.getElementById ("demo"). InnerHTML = "Port number is:" + _ window.location.port

Most browsers do not display the default port number (http is 8010 https and 443).

Window Location Assign

The _ window.location.assign () method loads the new document.

Example

Load a new document:

Function newDoc () {

_ window.location.assign ("https://www.w3school.com.cn")

}

Tags: Pages slogans instances documents methods hosts content properties ports learning practicality deeper Internet usage interest practicality practicality simple operation more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Redmi Linux Docker