tencent cloud

Tencent Cloud Observability Platform

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Basic Features
Basic Concepts
Use Cases
Use Limits
Purchase Guide
Tencent Cloud Product Monitoring
Application Performance Management
Mobile App Performance Monitoring
Real User Monitoring
Cloud Automated Testing
Prometheus Monitoring
Grafana
EventBridge
PTS
Quick Start
Monitoring Overview
Instance Group
Tencent Cloud Product Monitoring
Application Performance Management
Real User Monitoring
Cloud Automated Testing
Performance Testing Service
Prometheus Getting Started
Grafana
Dashboard Creation
EventBridge
Alarm Service
Cloud Product Monitoring
Tencent Cloud Service Metrics
Operation Guide
CVM Agents
Cloud Product Monitoring Integration with Grafana
Troubleshooting
Practical Tutorial
Application Performance Management
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Parameter Information
FAQs
Mobile App Performance Monitoring
Overview
Operation Guide
Access Guide
Practical Tutorial
Tencent Cloud Real User Monitoring
Product Introduction
Operation Guide
Connection Guide
FAQs
Cloud Automated Testing
Product Introduction
Operation Guide
FAQs
Performance Testing Service
Overview
Operation Guide
Practice Tutorial
JavaScript API List
FAQs
Prometheus Monitoring
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Terraform
FAQs
Grafana
Product Introduction
Operation Guide
Guide on Grafana Common Features
FAQs
Dashboard
Overview
Operation Guide
Alarm Management
Console Operation Guide
Troubleshooting
FAQs
EventBridge
Product Introduction
Operation Guide
Practical Tutorial
FAQs
Report Management
FAQs
General
Alarm Service
Concepts
Monitoring Charts
CVM Agents
Dynamic Alarm Threshold
CM Connection to Grafana
Documentation Guide
Related Agreements
Application Performance Management Service Level Agreement
APM Privacy Policy
APM Data Processing And Security Agreement
RUM Service Level Agreement
Mobile Performance Monitoring Service Level Agreement
Cloud Automated Testing Service Level Agreement
Prometheus Service Level Agreement
TCMG Service Level Agreements
PTS Service Level Agreement
PTS Use Limits
Cloud Monitor Service Level Agreement
API Documentation
History
Introduction
API Category
Making API Requests
Monitoring Data Query APIs
Alarm APIs
Legacy Alert APIs
Notification Template APIs
TMP APIs
Grafana Service APIs
Event Center APIs
TencentCloud Managed Service for Prometheus APIs
Monitoring APIs
Data Types
Error Codes
Glossary

URL Overview

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-03-11 20:21:20
url.URL can be used for URL-related operations.

Constructor

Create an object instance using new, as shown below:
new URL(url: string, base?: string | URL): URL

Parameters

Parameter
Type
Description
url
string
The Uniform Resource Locator.
base?
string or URL
The protocol and host portions of the Uniform Resource Locator, which will be overridden if not included in the URL.

Methodology

Methodology
Return Type
Description
hash()
string
Get the fragment portion of the URL.
void
Set the fragment portion of the URL.
host()
string
Get the host portion of the URL.
void
Set the host portion of the URL.
string
Get the host name portion of the URL.
void
Set the host name portion of the URL.
string
Get the serialized URL.
void
Set the serialized URL.
origin()
string
Obtain the read-only serialized string of the origin of the URL.
string
Get the password portion of the URL.
void
Set the password portion of the URL.
string
Get the path portion of the URL.
void
Set the path portion of the URL.
port()
string
Get the port portion of the URL.
void
Set the port portion of the URL.
string
Get the protocol portion of the URL.
void
Set the protocol portion of the URL.
search()
string
Get the serialized query portion of the URL.
void
Set the serialized query portion of the URL.
Get the URLSearchParams object representing the URL query parameters.
string
Get the username portion of the URL.
void
Set the username portion of the URL.
toJSON()
string
Return the serialized URL, this method is automatically called when the URL object is serialized with JSON.stringify().
string
Return the serialized URL.

Samples

Create a URL object without using the base parameter:
import url from 'pts/url';

export default function () {
const u = 'http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker';
const u0 = new url.URL(u)
console.log(u0.toString()); // http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker
}
Create a URL object using the base parameter:
import url from 'pts/url';

export default function () {
const u = '/test/index.html?name=xxx&age=18#worker';
const u0 = new url.URL(u, 'https://console.tencentcloud.com:8080')
console.log(u0.toString()); // https://console.tencentcloud.com:8080/test/index.html?name=xxx&age=18#worker
}
Perform related operations using the URL object:
import url from 'pts/url';

export default function () {
const u = 'http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker';

const u1 = new url.URL(u);
console.log('hash1 ', u1.hash()); // #worker
u1.setHash('hash');
console.log('hash2 ', u1.hash()); // #hash

const u2 = new url.URL(u);
console.log('host1 ', u2.host()); // www.example.com:8080
u2.setHost('host');
console.log('host2 ', u2.host()); // host

const u3 = new url.URL(u);
console.log('hostname1 ', u3.hostname()); // www.example.com
u3.setHostname('hostname');
console.log('hostname2 ', u3.hostname()); // hostname

const u4 = new url.URL(u);
console.log('href1 ', u4.href()); // http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker
u4.setHref('https://console.tencentcloud.com');
console.log('href2 ', u4.href()); // https://console.tencentcloud.com/

const u5 = new url.URL(u);
console.log('origin1 ', u5.origin()); // http://www.example.com:8080

const u6 = new url.URL(u);
console.log('pathname1 ', u6.pathname()); // /test/index.html
u6.setPathname('pathname');
console.log('pathname2 ', u6.pathname()); // pathname

const u7 = new url.URL(u);
console.log('port1 ', u7.port()); // 8080
u7.setPort('80');
console.log('port2 ', u7.port()); // 80

const u8 = new url.URL(u);
console.log('protocol1 ', u8.protocol()); // http:
u8.setProtocol('protocol');
console.log('protocol2 ', u8.protocol()); // protocol:

const u9 = new url.URL(u);
console.log('search1 ', u9.search()); // ?age=18&name=xxx
u9.setSearch('search');
console.log('search2 ', u9.search()); // ?search=

const u10 = new url.URL(u);
console.log('searchParams1 ', u10.searchParams()); // [object Object]

const u11 = new url.URL(u);
console.log('username1 ', u11.username()); // user
u11.setUsername('username');
console.log('username2 ', u11.username()); // username

const u12 = new url.URL(u);
console.log('password1 ', u12.password()); // pass
u12.setPassword('password');
console.log('password2 ', u12.password()); // password

const u13 = new url.URL(u);
console.log('toJSON1 ', u13.toJSON()); // http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker

const u14 = new url.URL(u);
console.log('toString1 ', u14.toString()); // http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker
}


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan