开发者

How to insert music in a website? [duplicate]

This question already has answers here: Closed开发者_开发问答 12 years ago.

Possible Duplicate:

Integrate a mp3 player into a page with no reloading issue

I have a website of 10 webpages and I want to insert an automatic playing song in this site.

However I want that when I click on another webpage of this site then the music doesn't stop.

Is this a way to do this without using iframe or flash ?


EDIT: I did not read your question fully. Unless you are using frames or Ajax for navigation (as in Gmail or New Twitter), this is not possible.

Old method

<BGSOUND SRC="aladdin.mid" LOOP=10>

Or use HTML 5

<audio autoplay id="bgsound">
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.mp4"
         type="audio/mp4">
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.oga"
         type="audio/ogg; codecs=vorbis">
 <p>Your user agent does not support the HTML5 Audio element.</p>
</audio>
<button type="button"
        onclick="document.getElementById('bgsound').pause();">
  Stop background sound
</button>

<p>
You'll probably annoy your readers if you use background sounds in documents.
</p>


First of all: don't start play music automatically on a webpage, let the user decide about to start the music or not.

You should put all your webpages into a long webpage, each one into a DIV:

<div id="page1">
 content of page 1
</div>
<div id="page2" style="display: hidden">
 content of page 2
</div>
<!-- etc. -->

Except the first one, hide the divs by CSS or style tag, see example. Then all the links pointing to other pages should call a small javascript code, which changes the visibility of the divs, turning the "referenced" one visible and hide others:

<a href="#" onclick="switchToPage(2)"> go to page 2 </a>

The player should be placed before the divs, or anywhere. The advantage of this method, that you may make a fix footer, header etc., and change only the content area. The disadvantage is that search engines will only see a long page instead of 10.

But again: don't make a webpage which starts playing music automatically!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜