开发者

flash element inside href

Using the following code:

<a href="/someurl">
  <div class='mydiv' 
   onMouseOv开发者_如何学JAVAer="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>

Triggering play() and stop() works as expected, however the href doesn't do much, as the click event is sent to the flashplayer, and not following the hyperlink.

I have several such flashplayers on the page, and I'm trying to find a way to 'activate' the href onClick and honor the url specified in the <a href=""> construct. Specifically, it's in IE8 I'm struggling.

How can I do this using html/javascript?

*Edit:

After having come across javascript onclick event over flash object I managed to get closer to what I'm after. Using the onmousedown event, I can trigger javascript when clicking my overlay div. What's a good generic way to read the parent href url and issue 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; ?

Why watching for onmousedown on the div? I made a jsfiddle demonstrating the extraction of the link attribute of each anchor tag on the page, just replace the alert(link) with window.location(link). You could also use getElementsByClassName instead of getElementsByTagName if there are just some links you want to fix.

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);
    }
}

update: inserted codesnippet

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜