All About Code

4 days ago

Photo by Frida Bredesen on Unsplash

How do you redirect to another page in Javascript?

There are many ways to redirect to another page. But which is the best?

// 1. window.location
window.location.href = ''
document.location.href = '/path'
// 2. window.history
// 3. window.navigate; ONLY for old versions of Internet Explorer
// 4. More ways... but probably not a good…



5 days ago

Here is the JavaScript.

function playAudio(url) {
new Audio(url).play();

Here is the HTML.

<img src="image.png" onclick="playAudio('mysound.mp3')">

If you experience a delay, use var audio = new Audio(url); once on page load. Then trigger it by audio.currentTime = 0;;. Resetting current time is only needed if the sound is…