js与flash交互
js操作flash比如播放、暂停等,这个要flash程序自己暴露这些接口才行,它没有暴露,那js是无能为力的。(网上js中控制flash的函数,我都试了下,没有用……)
flash会至于顶层,点击flash的点击事件会被flash捕获,包裹flash的div这些是无法捕获点击事件onclick的。有两种方式捕获点击:
- 在外层div 中 添加onmousedown="test2()",如 <div id="wrapper" style="width: 120px; height: 600px; position: relative" οnmοusedοwn="test2()" > 在chrome中无法播放flash
- 在flash的object标签中添加 onmouseup="test()",如 <object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="120" height="600"
οnmοuseup="test()"> 在chrome中可以播放flash
js控制点击flash跳转
1.http://www.cnblogs.com/dudumao/p/3599486.html(第三种里面说添加透明链接图片,应该直接用空格( )链接就可以)
2.只适用于chrome 45以上:第一次点击时播放flash,触发 onmouseup 调用test(),使得链接跳转顶置,再次点击时,就点击到了链接就会跳转了。
修改层次
var adlink=document.getElementById("adlink");
adlink.style.zIndex=3;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body{padding: 0;margin: 0;background: transparent;}
#top{text-align: center;overflow: hidden}
#wrapper{overflow: hidden; position: relative;margin: auto;text-align: left;}
</style>
<title>show</title>
<script type="text/javascript" src="http://img2.ad.agrantsem.com//js/swfobject.js"></script>
<script type="text/javascript">
swfobject.registerObject("myId", "9.0.115");
</script>
</head>
<body marginwidth="0" marginheight="0">
<script>
function test()
{
alert("flash点击了!");
var adlink=document.getElementById("adlink");
adlink.style.zIndex=3;
}
</script>
<div id="top" style="width: 120px; height: 600px;">
<div id="wrapper" style="width: 120px; height: 600px; position: relative" >
<div style="position: absolute; z-index:2">
<object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="120" height="600"
οnmοuseup="test()">
<param name="movie"
value="xxx.swf"/>
<!--[if !IE]>-->
<object type="application/x-shockwave-flash"
data="xxx.swf" flashvars="xx" width="120" height="600" >
<!--<![endif]-->
<!-- Alternative image below:-->
<div>
<a href="xxx" target="_blank"><img src="http://img2.ad.agrantsem.com//ad.jpg" style="border:none;"
alt="AGrant Ads"/> </a>
</div>
<!--[if !IE]>-->
<param name="wmode" value="opaque"/>
</object>
<!--<![endif]-->
<param name="quality" value="High"/>
<param name="wmode" value="opaque"/>
<param name="src"
value="xxx.swf"/>
<param name="menu" value="-1"/>
<param name="allowScriptAccess" value="always"/>
<param name="scale" value="ShowAll"/>
<param name="deviceFont" value="0"/>
<param name="embedMovie" value="0"/>
<param name="seamlessTabbing" value="1"/>
<param name="flashvars" value="xxx">
<embed src="xxx.swf"
wmode="Opaque" flashvars="" quality=high width="120" height="600" type="application/x-shockwave-flash"
/>
</object>
</div>
<div style="position: absolute;left:0px; top:0px;z-index:1"><a
href=http://www.baidu.com> </a></div>
<div id="adlink" style="position: absolute; width: 120px; height: 600px;z-index:1">
<a href="xxxx" target="_blank" style="position: absolute; width: 100%; height: 100%; outline: none;
font-size: 900px;"> </a>
</div>
</div>
</div>
</body>
</html>
flash与浏览器
目前只有chrome 45 禁用了小flash的自动播放,要手动点击才能播放