Узел | URL.hash API
Опубликовано: 6 Августа, 2021
Url.hash - это встроенный интерфейс прикладного программирования для класса URL с модулем in url, который используется для получения и установки фрагмента URL.
Синтаксис:
url.hash
Возвращаемое значение: получает и устанавливает фрагмент URL-адреса.
Ниже приведены программы, иллюстрирующие использование метода url.hash :
Пример 1:
// node program to demonstrate the // url.hash API as Setter // creating and initializing myURL // Display href value of myURL before change console.log( "Before Change" ); console.log(myURL.href); // assinging fragment portion // using hash console.log(); myURL.hash = "rahim" ; // Display href value of myURL after change console.log( "After Change" ); console.log(myURL.href); |
Выход :
Перед изменением https://example.org/foo#ram После изменения https://example.org/foo#rahim
Пример 2:
// node program to demonstrate the // url.hash API as Getter // creating and initializing myURL // getting the fragment portion // using hash const hash = myURL.hash; // Display hash value console.log(hash); |
Выход:
#баран
ПРИМЕЧАНИЕ . Вышеупомянутую программу можно запустить с помощью команды node myapp.js .
Справка:
https://nodejs.org/dist/latest-v10.x/docs/api/url.html#url_url_hash