Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions JavaScript_Advance/BOM_functions_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable no-multiple-empty-lines */
/* eslint-disable no-multi-spaces */
/* eslint-disable no-trailing-spaces */

/**
* History API
* Interface manipulates browser history in the session borders
*
* Fields
* @return {length} integer amount of elements in session history
* @return {state} field stories state existed page
*
* Methods
* @return {go} method loads a page from the session history with integer args
* @return {back} method goes to the previous page in session history the same as history.go(-1)
* @return {forfard} method goes to the next page in session history the same as history.go(1)
*
* @return {pushState} method pushes the given data onto the session history stack with the specified title and, if provided, URL
* @return {replaceState} updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL
*/

window.history.back(); // goes to the previous page or do nothing if the existed page is first
window.history.go(-1); // the same as above

window.history.forward(); // goes to the next page or do nothing if the existed page is last
window.history.go(1); // the same as above

console.log(window.history.state); // null if not specified for existed page

const stateData = "stateData";
const title = "title"; // ignored FireFox
const url = window.location.href; // url which can be used manually later if needs
window.history.pushState(stateData, title, url);

console.log(window.history.state === stateData); // true

window.history.replaceState(stateData, title, url); // to update existed state


/**
* Navigator API
* provides the user-agent information
* @return {userAgent} user agent string for the current browser
* @return {language} language of the browser UI
* @return {languages} list of languages known to the user
*
* Also contains a lot of user-agent information related to:
* - media devices
* - bluetooth
* - usb
* - geo location
* - etc.
*
* the full list of data is https://developer.mozilla.org/en-US/docs/Web/API/Navigator
*
* @return {serviceWorker} provides access to registration, removal, upgrade, and communication with service worker
*/

// usually is used custom function to define client browser type to specify which features can be used
// mostly for IE
const isIE = () => {
const isIE11 = navigator.userAgent.indexOf(".NET CLR") > -1;
const isIE11orLess = isIE11 || navigator.appVersion.indexOf("MSIE") !== -1;
return isIE11orLess;
};
36 changes: 36 additions & 0 deletions docs/JavaScript_Advance/BOM_functions_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# History / Navigator

## History API [MDN](https://developer.mozilla.org/ru/docs/Web/API/History)

Interface manipulates browser history in the session borders

Fields

- {length} integer amount of elements in session history
- {state} field stories state existed page

Methods

- {go} method loads a page from the session history with integer args
- {back} method goes to the previous page in session history the same as history.go(-1)
- {forfard} method goes to the next page in session history the same as history.go(1)
- {pushState} method pushes the given data onto the session history stack with the specified title and, if provided, URL
- {replaceState} updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL

## Navigator API [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator)

provides the user-agent information

- {userAgent} user agent string for the current browser
- {language} language of the browser UI
- {languages} list of languages known to the user

Also contains a lot of user-agent information related to:

- media devices
- bluetooth
- usb
- geo location
-- etc.

##### {serviceWorker} provides access to registration, removal, upgrade, and communication with service worker