My widget, loaded as an iframe, requires data about the hosting page. I have UTF-8 strings extracted from a page with Russian text. The page itself has proper HTML5 doctype and meta charset.
This is how my code operates:
params = "x1=" + encodeURIComponent(s1) + "&x2=" + encodeURIComponent(s2)
url = "http://mysite.com/iframe.html#" + params
create_iframe(url)
The create_iframe function looks something like this:
var $if, doc;
$if = $('<iframe>').attr({
frameborder: 0,
scrolling: "no",
allowtransparency: "true"
}).css(css).appendTo($cont);
doc = $if[0].contentWindow.document;
doc.open().write("<head><meta charset=\"UTF-8\"><script>" +
"var s = \"" + url + "\";" + // <--- here the url is injected into the iframe content
"function init() { document.location.href = s; }" +
"</script></head><body onload=\"init();\">...</body>");
doc.close();
We use jQuery to generate an iframe and then write to its content to load our url
.
Once the "" URL loads within the iframe, the script contained in it retrieves the parameter values from the hash:
var hash_index, loc, param, params, params_array, params_string, tmp, _i, _len;
loc = document.location.href;
hash_index = loc.indexOf('#');
if (hash_index >= 0) {
params_string = loc.substring(hash_index + 1);
}
params_array = params_string ? params_string.split('&') : [];
params = {};
for (_i = 0, _len = params_array.length; _i < _len; _i++) {
param = params_array[_i];
tmp = param.split('=');
params[tmp[0]] = decodeURIComponent(tmp[1]);
}
return params;
This process works smoothly in Chrome.
In IE8, I encounter an error indicating invalid encoding when attempting to decode the URI.
What steps should I take to resolve this issue?