Perhaps you are aware of the compatibility issues that Google Chrome and Safari have when using navigatetoURL, as it only works in Internet Explorer. To address this problem, I found a code snippet on a forum which consists of a JavaScript function embedded in an HTML file. Additionally, there is another function in Flex that gets called when a button is clicked. Here's a snippet of the code:
variables.pmsg1 = xml_langue.msg1;
variables.pmsg2 = xml_langue.msg2;
variables.pmsg3 = xml_langue.msg3;
variables.pmsg4 = xml_langue.msg4;
variables.ppaytomode = parentApp.PAYTOMODE;
var request:URLRequest = new URLRequest(dir_web);
request.data = variables;
request.method = "GET";
//navigateToURL(request,"_blank");
postXMLPageRequest(variables, request.toString(), '_blank'); // HERE I AM CALLING THE FLEX FUNCTION
THE FLEX FUNCTION BELOW:
public function postXMLPageRequest(data:Object, pageURL:String, window:String=null):void { if (ExternalInterface && ExternalInterface.available) ExternalInterface.call("postXMLPageRequest", pageURL, data.encode().toString(), window); }
THE JAVASCRIPT FUNCTION (found in html file) BELOW:
function postXMLPageRequest(url, xmlString, target, method) { method = method || "POST"; target = target || "_blank";
<%----------------------------------------------------------%> <%-- Create a form element with the specified attributes. --%> <%----------------------------------------------------------%> var form = document.createElement("form"); form.setAttribute("action", url); form.setAttribute("method", method); form.setAttribute("target", target); form.setAttribute("ENCTYPE", "text/plain"); form.setAttribute("style", "display: none");
<%--------------------------------------------------------------------%> <%-- Add the XML string as the value to a hidden input to the form. --%> <%--------------------------------------------------------------------%> var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "' + xmlString); form.appendChild(hiddenField );
<%-----------------------------------------%> <%-- Add the form to the body, submit it --%> <%-- then remove the form from the body. --%> <%-----------------------------------------%> document.body.appendChild(form); form.submit(); document.body.removeChild(form); }
However, upon clicking the button that triggers the postXMLPageRequest function, nothing seems to happen. Can anyone provide insight into solving this issue?
Thank you!