使用以下代码:
<a href="/someurl">
<div class='mydiv'
onMouseOver="document.getElementById('myid').sendEvent('play');"
onMouseOut="document.getElementById('myid').sendEvent('stop');">
<div id='myid'></div>
<script type="text/javascript">
flashplayer.init('myid');
</script>
</div>
</a>
触发 play() 和 stop() 按预期工作,但是 href 没有做太多,因为点击事件被发送到 flashplayer,而不是跟随超链接。
我在页面上有几个这样的 flashplayer,我正试图找到一种方法来“激活”href onClick 并遵守 <a href="">
构造中指定的 url。具体来说,我在 IE8 中苦苦挣扎。
如何使用 html/javascript 执行此操作?
*编辑:
在遇到 javascript onclick event over flash object 之后,我设法接近了我所追求的目标。使用 onmousedown 事件,我可以在单击覆盖 div 时触发 javascript。读取父 href url 并发布 location.href='/myparenturl';" style="cursor: pointer;
的通用方法是什么?
最佳答案
What's a good generic way to read the parent href url and issue location.href='/myparenturl';" style="cursor: pointer; ?
为什么要关注 div 上的 onmousedown?我做了一个jsfiddle演示提取页面上每个 anchor 标签的link属性,只需将alert(link)
替换为window.location(link)
即可。您也可以使用 getElementsByClassName
而不是 getElementsByTagName
如果您只想修复一些链接。
var anchors = document.getElementsByTagName('a');
for(i = 0; i <= anchors.length; i++) {
var anchor = anchors[i],
link = anchor.getAttribute('href'),
div = anchor.childNodes[0];
div.onmousedown = function() {
alert(link);
}
}
更新:插入代码片段
关于javascript - href 内的 flash 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077636/