Асинхронно получить данные
Отрендерить часть страницы
Обновить адрес ресурса без перезагрузки
history.length;
history.back();
history.forward();
history.go(-2);
history.go(2);
history.pushState(state, title, pathname);
history.pushState(null, null, '/films/warcraft');
const state = { title: 'Warcraft', text: '...' };
history.pushState(state, null, '/films/warcraft');
console.log(history.state);
// { title: 'Warcraft', text: '...' }
Состояние должно быть cериализуемо
И ограничено размером (640k в Firefox)
const state = { title: 'Warcraft', text: '...' };
history.pushState(state, null, '/films/warcraft');
addEventListener('popstate', event => {
console.log(document.location.pathname, event.state);
});
history.back();
// '/' null
history.forward();
// '/films/warcraft' { title: 'Warcraft', text: '...' }
const state = { openedTab: 'trailers' };
const pathname = document.location.pathname;
history.replaceState(state, null, pathname);
history.scrollRestoration = 'manual'; // auto, по умолчанию
Для орков нет другой жизни кроме войны
const selection = window.getSelection();
// Выделить текст в domNode и всех вложенных нодах
selection.selectAllChildren(domNode);
// Вернуть текст
selection.toString();
// Удалить выделение
selection.removeAllRanges();
// Скопировать в буфер
document.execCommand('copy');
// Событие копирования в буфер
window.addEventListener('copy', () => {});
// Событие вставки из буфера
window.addEventListener('paste', event => {
event.clipboardData.getData('text/html');
event.clipboardData.getData('text/plain');
});
<input id="message">
<button data-clipboard-target="#message"></button>
const clipboard = new Clipboard('button');
clipboard.on('success', event => {
const text = event.text;
event.clearSelection();
});
<div contenteditable></div>
<div contenteditable spellcheck></div>
document.execCommand('bold')
document.execCommand('createLink', false, 'https://ya.ru/')
document.execCommand('insertHTML', false, '<p>Awesome!</p>');
document.queryCommandSupported('createLink');