I'm looking for the autoplay code please [getElementById]

Can you check that it works on here first before sending me the code.

I’m looking for the autoplay code please.
var player = document.getElementById('player').

<button id="playButton" style="border:none; width: 200px; height: 200px; cursor: pointer; font-family:Tahoma; font-weight: bold;font-size:14px; background-color:red;color:blue;" onclick="  
var player = document.getElementById('player').volume='1.0';
var button = document.getElementById('playButton');
  var player = document.getElementById('player');
  if (player.paused) {
playButton.style.backgroundColor = 'red';

player.play();
  } else {
   
playButton.style.backgroundColor = 'red';
   
player.pause();
  }">
  </button>

<audio id="player" style="display:none;">
  <source src='http://hi5.1980s.fm/;' type='audio/mpeg' />
</audio>

I’m looking for the autoplay code please.

Seriously? Why? Did you not understand any of the explanations as to why it’s not a good idea to use autoplay?

https://www.sitepoint.com/community/t/is-there-anything-you-would-change-about-my-code-and-if-so-what/229753/15?u=technobear

https://www.sitepoint.com/community/t/is-there-anything-you-would-change-about-my-code-and-if-so-what/229753/18?u=technobear

Handy Hint: If you took the time to read all various resources we keep supplying links for, you wouldn’t need to ask this question at all. The answer is in a resource I linked to yesterday.

5 Likes

my page is a music page so anyone who goes on it will be expecting music.

no they wont - you don’t have anything anywhere to indicate that it is a music page

2 Likes

I can add volume controls to it.

<button onclick="document.getElementById('player').volume += 0.1">Vol+ </button>
<button onclick="document.getElementById('player').volume -= 0.1">Vol- </button>

why are you constantly writing JUNK. That might be appropriate way to code it for Netscape 4 but that way of coding has been dead for over 10 years and is now considered to be nothing but a security hole that can be blocked using security headers to prevent such code from working.

You really need to learn HTML before continuing to ask constant questions about which pile of security hole JUNK is better than which.

All of your JUNK is equally open to your pages being used to install viruses and worse onto people’s computers. Plus it actually looks like JUNK in most browsers at most resolutions.

1 Like

Why not just stick to having proper “play/pause/stop” controls so that visitors can choose whether or not they want to listen? You now have several versions of those, provided by various people here and at Stack Overflow.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.