How to autoplay the link in Anchor tag

Hello all,

    I have to play a audio file on my web page automatically. I am using Yahoo Media Player.

Right now I am playing the audio like this....

    <script type="text/javascript" src=""></script>

<td>  <a  id= "songlink" runat = "server"  visible ="false" >Play Advertisement</a>

I am giving the href in code behind( based on the user location)

Code Behind:

                        songlink.HRef = "Media/song1.mp3"
                        songlink.Visible = True

With this method, I have to click on the link, to play the song..

But, I would like to play the song automatically( without any click) . Is it possible to do so from code behind?

Appreciate the help

Who is Participating?
shahjagatAuthor Commented:
Hello All,

   I ended up using this script. Works perfect..

/** On Yahoo Media API Ready **/
var yesReady = false;
  yesReady = true;

function play(){

  //Capture the URL of the song
  var url = document.getElementById('<%=hidurl.ClientID %>').value;
  //Put it in Href of Song Link
  document.getElementById("<%=songlink.ClientID %>").href = url;

  //After that Play the Song using YMP
    YAHOO.MediaPlayer.addTracks(document.getElementById('songdiv'), 0, true);;

<td align = "center"  >
                                      <div id='songdiv'>
                            <a  id= "songlink" runat = "server"  style="font-size:large ; color: Blue; background-color: Silver; border-color: Maroon"   >Click here to Play Advertisement</a>
                               <asp:HiddenField ID="hidurl" runat="server"  Value = ""></asp:HiddenField> </td>

Thank you all.
shahjagatAuthor Commented:
Hello CodeCruiser,

  The song comes from my side, I am just using the yahoo media player to play the song.

I am changing the Href of the anchor tag from code behind.
Song1.mp3 comes from the Media folder of my project.

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Gurvinder Pal SinghCommented:
check this solution

just check if you can change the source of embed object from code behind
shahjagatAuthor Commented:
Hello gurvinder,

  This web app will be used in the tablets, so there will be now mouseover and I would like to have the audio played without any click . Is it possible?

shahjagatAuthor Commented:
autoplay using javascript worked fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.