jQuery click event not redirecting to href
I've got an HTML page with an embedded flash movie, which has a button. This button in flash invokes the lnkEmail's click event. It's supposed to stop from actually navigating to a new page, but the event.preventDefault(); and the returning of false from the event handler don't seem to be working for me. Can anyone provide insight?
The below example is working in Chrome, but fails in IE 7 and FF. In those browsers it redirects to a blank page with Object [object] as the body and in FF has the url set to the javascript code I execute from within the Flash movie. (ie: "javascript:jQuery('#lnkEmail').click();")
Below is the code in the Flash ActionScript.
cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
navigateToURL(
new URLRequest(
"javascript:jQuery('#lnkEmail').click();"
),
"_self"
);
}
In the containing HTML page there is the following scripts and elements:
<script type="text/javascript">
$(function(){
$.nyroModalSettings({
debug: true
});
$('#lnkEmail').click(function(event) {
event.preventDefault();
$.nyroModalManual({
url: 'demoRequest.aspx?Type=4'
});
return false;
});
});
</script>
And later in the same file:
<div id="box_stage_home">
<script type="text/javascript">
$(document).ready(function() {
$('#HomeAnimation').flash({
swf: 'Flash/index_page.swf',
height: 288,
width:开发者_JS百科 686,
wmode: 'transparent'
});
});
</script>
<div id="HomeAnimation"><!--IE 6.0--></div>
<a href="emailSend.aspx?Type=4" id="lnkEmail"> </a>
</div>
Take a look at the navigateToURL
documentation: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL%28%29. It is not intendend to be used with javascript:
links.
To do what you want, use ExternalInterface.call()
.
Figured out the proper way (thanks corneliu) to do this so thought I'd post it back on here for reference. In the html file:
<script type="text/javascript">
function viewDemo() {
$.nyroModalManual({
url: 'emailSend.aspx?Type=4'
});
}
</script>
In the flash file:
import flash.system.Security;
cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
flash.system.Security.allowDomain("business.com");
ExternalInterface.call("viewDemo");
}
精彩评论