Window object (one) Timer location navigation URL Resolution Browse History dialog message push

Source: Internet
Author: User

Window object

Timer

A jquery writer writes about the timer explanation and registers it with a subscription. The father of John Resig,jquery
https://johnresig.com/blog/how-javascript-timers-work/
If the time is 0, it is placed in the queue, called by the queue, which is the producer-consumer model
A chestnut

function invoke(f, start, interval, end) {    if (!start) start = 0;  // 默认设置为 0 毫秒,如果传入有值,将会不进行设置    if (arguments.length <= 2) {    // 如果没有传入end的值        setTimeout(f, start);   // 函数f将会在start秒后调用    } else {    // 如果传入的值有end        setTimeout(repeat, start);  // 将会在start毫秒后执行repeat        function repeat() { // 开始定义repeat函数            var h = setInterval(f, interval)    // 在interval循环调用f            // 在end毫秒以后停止调用。            if (end) {  // 再次判断end是否存在                setTimeout(() => {                    clearInterval(h);   // 清除定时任务                }, end);            }        }    }}
Browser positioning and navigation

The Location property of the Window object refers to the Location object.
Https://developer.mozilla.org/zh-CN/docs/Web/API/Location
Because of referential relationships, the following equations are always true

location === document.location;true
URL parsing

Extracting parameters from a URL search string

/* *  这个函数解析url查询串中的name=value字符串 *  它将 name=value 对储存在一个对象的属性中,并返回该对象 *  使用方法 * *  var args = urlArgs();   // 调用定义好的函数,进行解析 *  var q = args.q || "";   // 一个判断,如果参数存在使用参数,否则使用"" * */function urlArgs() {    var args = {};    var query = location.search.substring(1);   // 获得问号后面的内容    var pairs = query.split("&");   // 将字符串进行分割 按照& 即进行分项    for(var i = 0; i < pairs.length; i++){  // 进行依次遍历        var pos = pairs[i].indexOf(‘=‘);    // 进行查找是否有= 没有返回-1 有返回等号所在的索引        if (pos == -1) {    // 如果没有 ‘=’            continue;   // 跳过循环        };        var name = pairs[i].substring(0, pos);  // 因为后一个是不包括,所以返回=前面的内容        var value = pairs[i].substring(pos+1);  // 返回等号后的结果        args[name] = value; // 对键值对进行存储     };    return args;    // 返回数组};
Loading a new document
// 更改location属性使得网页跳转location = "http://www.iming.info/"// 将相对url赋值给location达到对当前url解析的目的location = "page2.html";// 跳转到文档的顶部,跳转页面向上location = "#top"   // 如果 #top没有定义// 字符串拼接urllocation.search = "?page" + (pagenum + 1);  // 加载一个新文档,更改href的值也同理location.hash = pagenum;    // 将会在当前文档跳转到id为pagenum的标注点
Browse History

The History property of the Window object references the History object
The script cannot access the URL that has been saved
Length indicates history in the browse list
Note: Just the browsing history of the current tab, because each open tag is equivalent to creating a new thread (sometimes the browser will automatically merge the threads) so that the JS threads between each other are independent and cannot be accessed by each other.

// 单击浏览器的后退按钮2次、history.go(-2)// 单击浏览器的前进按钮2次history.go(2);

This can happen due to the presence of Ajax technology.

Browser and screen Information Navigator objects

The object was named to commemorate the distant Netscape browser, (@ο@)
Know, long insight, Netscape browser English name; Netscape Navigator an era. Unfortunately, I missed it. Oh ~

PS has been dropping Google Chromem for 10 years. 2008 to 2018, full 10 years

can be based on

navigator.userAgent

Gets some information about the current browser.
For example

navigator.userAgent"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"

This is based on Mozilla Open source project Firefox browser, its kernel is Gecko version number 20100101 Firefox version number 61.0, based on the Mozilla Project Open source version number 5.0

Mozilla was founded by Netscape, but now with the radical disappearance of Netscape, the community now becomes an open source organization. belongs to the Mozilla Foundation. It's been 20 years.

Historical https://en.wikipedia.org/wiki/History_of_the_Internet

navigator.userAgent"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36"

Indicates that the version of browser four AppleWebKit kernel is 537.36 Chrome and version 68. 0 Safari for 537.36

Screen Object

The Window object refers to the screen object

Screen { availWidth: 1378, availHeight: 900, width: 1440, height: 900, colorDepth: 24, pixelDepth: 24, top: 0, left: 0, availTop: 0, availLeft: 0 }
Screen {availWidth: 1378, availHeight: 900, width: 1440, height: 900, colorDepth: 24, …}availHeight:900availLeft:0availTop:0availWidth:1378colorDepth:24height:900orientation:ScreenOrientation {angle: 0, type: "landscape-primary", onchange: null}pixelDepth:24width:1440

Can get some information about the current browser, such as screen size, resolution, etc.

dialog box A desktop message push

Google browser support desktop message push (Shell browser is also supported, is a kernel, does not care support does not support)
Https://developers.google.com/web/fundamentals/codelabs/push-notifications/?hl=zh-cn
Https://crxdoc-zh.appspot.com/apps/inform_users
GitHub Source Https://github.com/GoogleChromeLabs/web-push-codelab
Can implement desktop message push,
In the future will be dedicated to write a push, is now more curious about this push process. It's not too hard to look at.
and Chrome's blog https://developer.chrome.com
A self-organizing chrome app extension
But it all seems out of date.
GitHub Https://github.com/GoogleChrome
and https://developers.google.com/web/fundamentals/
This is a tutorial place.
and Chromium blog https://blog.chromium.org/basically the Shell browser's kernel is based on chromium
And
https://blog.google/products/chrome/
Message push enables local message push, based on the system level.
Android can be based on the Chrome browser and is not familiar with the mobile side now. In the future, this is a place to make up,

Alert Confirm Prompt

Alert has only one OK button for warnings and other content
Confirm an optional message, along with two buttons, pops up under the center of the browser's address bar, Chromer so
Prompt displays a dialog box for prompting for input.
Give me a chestnut.

do {    var name = prompt("what is your name?");    // 弹出对话框,输入名字    var correct = confirm("you entered " + name + "\n" + "Click Okay to proceed or Cancel to re-eenter");   // 弹出一个对话框  ,将会返回一个布尔值} while(!correct)alert("hello, " + name);    // 弹出一个警告框

where confirm () and prompt () can cause blocking. That is, the content is not returned until the user shuts it down, meaning that the code stops running before a dialog box pops up. If the document is loading, it stops loading and waits for user input. Alert () also causes blocking
There is also a showmondaldialog () that displays an impersonation dialog box that contains the HTML format. You can pass in parameters and return values from the dialog box.
Be careful.

该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。

All right. This has been abandoned, so I don't learn it.

Error handling

Oneror has been abandoned.

Blog

Www.iming.info

Window object (one) Timer location navigation URL Resolution Browse History dialog message push

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.