JS - Other

Vibrate your Device

// vibrate device for 300 milliseconds
window.navigator.vibrate(300);


⚠️ Will not work if the device is in silent mode.

VM428:7 Uncaught TypeError: Cannot read properties of null (reading 'CodeMirror') at anonymous:7:17

Remove Blackbox extension and react development tool extension from browser.

Wait Function

const wait = new Promise((resolve) => setTimeout(resolve, ms));

const asyncFunc - async() =>{
  await wait(1000);
  console.log('async')
}

asyncFunction();

Web Share API

The Web Share API allows you to share text, links, and even files from a web page to other apps installed on the device.

async function shareHandler() {
  navigator.share({
    title: "Tapajyoti Bose | Portfolio",
    text: "Check out my website",
    url: "https://...",
  });
}


NOTE: To use the Web Share API, you need an interaction from the user. For example, a button click or a touch event.

Window Location

http://localhost:4200/landing?query=1#2


window.location.hash: "#2"
​
window.location.host: "localhost:4200"
​
window.location.hostname: "localhost"
​
window.location.href: "http://localhost:4200/landing?query=1#2"
​
window.location.origin: "http://localhost:4200"
​
window.location.pathname: "/landing"
​
window.location.port: "4200"
​
window.location.protocol: "http:"

window.location.search: "?query=1"