This is my first question on Stack Overflow. It's not the first time I wanted to write one, but usually I find a solution using the search bar, this time I didn't. The problem I'm tackling is a little bit complex so I'll try and be as thorough as possibile.
Basically we're adding Chinese payments to an already existing ecommerce in Flash. The whole website is in AS3, embedded using SWFObject, already using ExternalInterface for other things.
This new Chinese payment method is a bit old-fashioned, so they have a strange way of handling payments. Once we've sent a POST to their servers with all the order details, they respond with an HTML page. My problem is rendering this page, considering that I receive it inside Flash.
The solution I'm trying at the moment works partially, meaning that I'm able to see the page, but the Chinese characters that are supposed to be in the page are rendering out badly. Instead of the Chinese characters I'm seeing weird characters, so I'm guessing there must be an encoding problem when I pass the HTML from Flash to Javascript. This is how I'm doing it:
AS3:
//extract html page from response
var newHTML:String = e.currentTarget.data;
//trim whitespace to avoid javascript error
newHTML = newHTML.replace(/\n/g, '');
newHTML = newHTML.split("\r").join("");
if(ExternalInterface.available)
ExternalInterface.call("chinesePayment('"+newHTML+"')");
else
trace("External interface error");
Javascript:
function chinesePayment(param) {
var newWindow = window.open();
//var unescaped = unescape(param);
newWindow.document.write(param);
}
I've tried messing about with unescape, escape, URIencoding but without any success, so I'm really hoping you can help me out here!
Thanks, Domenico
EDIT:
I'd just like to mention that I'm receiving a correct HTML page from their servers. I've tried saving the page locally, copying the HTML code directly from the server response, and the page views correctly. That means that there has to be something wrong in the process of passing the page from AS3 to Javascript.
EDIT2 !important:
I've realised that the problem lays in the popup encoding. When I copy the HTML from the popup, paste it in an editor and save it I can correctly view the HTML. Seems like the popup doesn't consider gbk encoding. I'm now looking for a solution to this problem.
encodeURIComponent
andunescape
, although I'm unfamiliar with Chinese symbols and how they are encoded:newWindow.document.write(unescape(encodeURIComponent(param)));
– Katharyn