javascript - if ("i am on this html page") { play this music}; -


if ("i on html page") {play music};

are there commands make possible using javascript?

this code worked me :)

var soundefx2 = document.getelementbyid("soundefx2"); var soundmain = "music/main.mp3"; if(window.location.href.split('/').pop() == "game2.html") {     soundefx2.src = soundmain;     soundefx2.play();     soundefx2.loop = true; } 

let's url http://foo.com/bar.html.

with window.location.href you're getting whole url (http://foo.com/bar.html), need last url segment (bar.html) of url, use:

if(window.location.href.split('/').pop() == "game2.html"){     // rest of code } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -