How to autoplay the link in Anchor tag

Posted on 2011-10-20
Last Modified: 2012-06-27
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

Question by:shahjagat
    LVL 83

    Expert Comment


    Author Comment

    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.

    LVL 40

    Expert Comment

    check this solution

    just check if you can change the source of embed object from code behind

    Author Comment

    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?


    Accepted Solution

    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.

    Author Closing Comment

    autoplay using javascript worked fine.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now