Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to autoplay the link in Anchor tag

Posted on 2011-10-20
Medium Priority
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="http://mediaplayer.yahoo.com/js"></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
  • 4
LVL 83

Expert Comment

ID: 37003306

Author Comment

ID: 37003357
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

by:Gurvinder Pal Singh
ID: 37004600
check this solution

just check if you can change the source of embed object from code behind
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 37006540
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

shahjagat earned 0 total points
ID: 37009183
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

ID: 37136782
autoplay using javascript worked fine.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
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)
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

577 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