Skip to content Skip to sidebar Skip to footer

Html Open New Tab With Playing Sound

I know how to open a new tab. For example, this is what I have: Award This code, wil

Solution 1:

Create a new html file in the same folder where is your pdf file located and put this code in that html file.

 <audio autoplay>
  <source src="youraudio.ogg"type="audio/ogg">
  <source src="youraudio.mp3"type="audio/mp3">
  Your browser does not support the audio element.
</audio> 
   <iframe id="viewer" src="yourpdffile.pdf" allowfullscreen="" webkitallowfullscreen="" height="500" width="700"></iframe>

save the file(change path in the code as necessary). Point the Anchor to the new html file.

<ahref="newhtmlfile.html"target="_blank"style="font-size:17px">Award</a></span>

Thats it.

Solution 2:

try setting onfocus and onblur events to your code:

ex:

window.onfocus=function(){
    //stop the music
}
window.onblur=function(){
    //play the music
}

note: this will not stop the music when you close the new tab, but only when you navigate back to the original tab.

see onfocus and onblur documentation for more details.

Solution 3:

Are you trying to open the new tab with the music "inside"? If so, it's not recommended but, let me try to help you.

You can display the .pdf using an iframe (it's not recommended too).

To play the audio you can use the audio tag by HTML5:

<audiosrc="audio.ogg"autoplayloop><p>Your browser does not support the audio element </p></audio>

And then, display the iframe below with the .pdf file.

<iframesrc="pdf.pdf"></iframe>

Don't forget to set the iframe to full page size.

Post a Comment for "Html Open New Tab With Playing Sound"