This post is very helpful for me to send small bits of information across iframes. However, this creates a new challenge with history manager that uses the same mechanism to store page state. Whenever an iframe uses fragment identifiers to send a message across iframes, the page state for the target iframe is wiped out. If the message leads to a new page state, this actually matches the intended use of history manager. However, for scenarios where the message does not lead to a new page state, it may lead to an inconsistent sate between the representation in the URL and what’s displayed on the target iframe. One work around is to reset or synchronize the page state for such use cases, which can generate unnecessary reload/AJAX calls. If you have a cleaner approach, let me know.
Posts Tagged HistoryManager
An encoding workaround
For the last couple days, I’ve been tweaking URL encoding with UTF-8 characters using JavaScript. I got an interesting situation where when the hash part of the URL (i.e. “mystate_information” in this URL http://myserver/myapp.html#mystate_information) works fine when it’s being updated by the JavaScript or the state manager. When loading the URL directory from bookmark or in the address bar, the state sometimes would get decoded before reach my state handling code instead passing in raw string. This means that the state sometimes is encoded and sometimes isn’t. This makes coding a little challenging.
Here is a workaround that I figured out. Since URL encoded text has “%” characters, I look for this character. If it exists, do the decoding. If not, skip decoding. Here is a simple sample code:
var input = mystate_information;
if(input.indexOf('%') != -1)
input = aDecodeFunction(mystate_information)
Do you know of a corner case that this might not work? Or do you have a smarter idea?
