javaScript实现背景音乐与播放声音
研究了半天,不过貌似还是只能在IE上实现,其他浏览器不支持EMBED 标签
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用javascript制作超链接的背景音效</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function controlSound(action)
{
var i; method = "";
var sndObj = document.getElementById("music");
if (sndObj != null)
{
if (navigator.appName == 'Netscape')
method = "play";
else
{
if (window.MM_WMP == null)
{
window.MM_WMP = false;
for(i in sndObj)
{
if (i == "ActiveMovie")
{
window.MM_WMP = true;
//alert("1");
break;
}
}
}
if (window.MM_WMP)
method = "play";
else if (sndObj.FileName)
method = "run";
}
}
if (method)
{
if(action=="stop")
method="stop";
alert(method);
eval("document.hidden_player"+"."+method+"()");
}
}
//-->
</script>
</head>
<body>
<a href="#" onMouseOver="controlSound('play','document.ailisi','2.mp3')"
onmouseout="controlSound('stop','document.ailisi','2.mp3')"
>背景音乐 鼠标移入播放 移出停
</a> <br>
<button onclick="controlSound('play')">播</button>
<button onclick="controlSound('stop')">停</button>
<!--src是音频的地址, hidden属性为隐藏-->
<EMBED NAME='hidden_player' SRC='1.wma
相关文档:
<iframe width='100%' height='100%' name='boot' id='boot' src='' frameborder='0' scrolling='no'></iframe>
<SCRIPT LANGUAGE="JavaScript">
<!--
var iframe = window.frames['boot'];
iframe.document.open();
iframe.document.write('<!DOCTY ......
在javascript代码中用encodeURIComponent()函数处理中文字符串,
JS代码:
<mce:script type=”text/javascript”><!--
string = encodeURIComponent(string);
location.href = index.php?keyword=’+string;
// --></mce:script>
PHP代码:
<?php
$keyword = (isset($_GET ......
先来看一个简单的例子:
下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。
Java代码
frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ......
要想写出跨浏览器的javascript,就必须懂得嗅探技术。这是浏览器大战遗留下的大地雷,事已如此,只好认命,乖乖写分支结构吧,函数就是这样不知不觉中变长的。
先看单一浏览器的判断,我们没有必须去找navigator.userAgent的麻烦,我在国外的博客网站收集了如下hack,短小精悍:
ie = !+"\v1" ;
ie ='\v'=='v' ; ......