選択している文字列の操作
Demo : http://codepen.io/mo4_9/pen/ObNjeR
window.getSelection()
windowを開く
Demo : https://codepen.io/mo4_9/pen/gGRgWa
let newWin;
const WIDTH = 400;
const HEIGHT = 300;
window.name = "openerWin"; // オープン元ウィンドウの名前
newWindow = window.open("subwindow.html", "newWindow", `status=1,width=${WIDTH},height=${HEIGHT}`);
newWindow.resizeTo(screen.availWidth/2, screen.availHeight/2);
newWindow.moveTo(screen.availWidth/2 - WIDTH/2, screen.availHeight/2 - HEIGHT/2);
プロパティを動的に生成
Demo : https://codepen.io/mo4_9/pen/OxgWjX
Computed property names
ブラケットで囲う
let i = 0;
const member = {
name: 'hoge',
age: 20,
[`memo${++i}`]: 'memo1',
[`memo${++i}`]: 'memo2',
[`memo${++i}`]: 'memo3'
}
console.log(member);
^ 消えたので画像も貼っておく
HISTORY API
Demo : http://codepen.io/mo4_9/pen/XNOZyB
let count = 0;
const result = document.getElementById("result");
document.getElementById("btn").addEventListener("click", (e) => {
if( window.history && window.history.pushState ){
result.textContent = ++count;
history.pushState(count, null, `${location.host}/${count}`)
console.log(`${location.host}/${count}`)
}
})
window.addEventListener("popstate", (e) => {
count = e.state;
result.textContent = count;
})
参考
【HTML5】HISTORY API「pushState/popState」を使って画面遷移しなくてもURLを変化させて、戻るボタンの挙動をカスタマイズする
pushState() + AJaxでスムーズなコンテンツの遷移