Professional JavaScript for Web Developers 第四版学习笔记 CHAPTER 12:The Browser Object Model

欢欢欢欢 发表于 2021-8-11 08:15

The window Object 438
The Global Scope 438
Window Relationships 439
Window Position and Pixel Ratio 439
 Pixel Ratios 439
Window Size 440
Window Viewport Position 441
Navigating and Opening Windows 442
 Popping Up Windows 442
 Security Restrictions 445
 Pop-up Blockers 445
Intervals and Timeouts 446
System Dialogs 448
The location Object 450
Query String Arguments 451
 URLSearchParams 452
Manipulating the Location 452
The navigator Object 454
Detecting Plug-ins 456
 Legacy Internet Explorer Plugin Detection 457
Registering Handlers 459
The screen Object 459
The history Object 460
Navigation 460
History State Management 461
Summary 462

-------------------------------------------------

URLSearchParams

let qs = "?q=javascript&num=10";
let searchParams = new URLSearchParams(qs);
alert(searchParams.toString()); // " q=javascript&num=10"
searchParams.has("num"); // true
searchParams.get("num"); // 10
searchParams.set("page", "3");
alert(searchParams.toString()); // " q=javascript&num=10&page=3"
searchParams.delete("q");
alert(searchParams.toString()); // " num=10&page=3"

-------------------------------------------------

location.replace()

This method accepts a single argument, the URL to navigate to, but does not make an entry in the history stack. After calling replace(), the user cannot go back to the previous page.

-------------------------------------------------

popstate

window.addEventListener("popstate", (event) => {
 let state = event.state;
 if (state) { // state is null when at first page load
  processState(state);
 }
});