Passive Listener

addEventListener(document, “touchstart”, function(e) { console.log(e.defaultPrevented); // will be false e.preventDefault(); // does nothing since the listener is passive console.log(e.defaultPrevented); // still false }, Modernizr.passiveeventlisteners ? {passive: true} : false);Continue reading

Forum

// create new element const elem = document.createElement(‘div’) elem.className = ‘quetxt’ // add text elem.innerText = ‘Question:’ elem.style = ‘color:#d55900; font-weight:700; font-size: 18px; margin-top:15px; margin-bottom:10px; font-family:Georgia;’ // grab target element reference const target = document.querySelector(‘.article-header’) // insert the element before…Continue reading

Prevent Copy Paste

document.addEventListener(“contextmenu”, (evt) => { evt.preventDefault(); }, false); document.addEventListener(“copy”, (evt) => { evt.clipboardData.setData(“text/plain”, “You must pay a premium subscription to copy our content”); evt.preventDefault(); }, false);Continue reading