Skip to content

Issues with colons in messages to the child frame #246

Closed
@xss

Description

@xss

This might be a regression of an issue fixed in v2.4.8.

In order to receive messages from the parent window (via iframe.iFrameResizer.sendMessage()), I defined the following within the child iframe before loading the iframeresizer.contentwindow.js:

<script>
window.iFrameResizer = {
    messageCallback: function (messageData) {
        // Do something with messageData which is the plain text sent from the parent
        // via iframe.iFrameResizer.sendMessage().
        // ATTENTION: Contrary to messageCallback() on the parent side, the message 
        // text resides directly in messageData here, *not* in messageData.message!
    },
};
</script>
<script src="js/iframeresizer.contentwindow.js"></script>

Aside from the issue with the differences between messageCallback() in the parent frame and the child frame, I cannot send messages containing a colon (:) character to the child iframe. For some reason, the message seems to automatically be parsed with JSON.parse() by the child iframe, but whatever string it gets passed for parsing, the colon always results in an error:

[iFrameSizer][Host page][Send Message] Sending msg to iframe[resizable] (message:"hello: you!")
[iFrameSizer][resizable] MessageCallback called from parent: "hello
SyntaxError: JSON.parse: unterminated string at line 1 column 7 of the JSON data

Usage of single-quotes or double-quotes doesn't seem to make a difference here.

I stumbled upon this as I was trying to send JSON formatted messages to the child, the same way I can send it from the child iframe to the parent window. By now I resorted to sending some kind of "pseudo-JSON" message from the child (iframe.iFrameResizer.sendMessage('{"message" => "parent says hello."}'); which I convert to real JSON within the child (messageData = messageData.replace(/\ ?\=\>/g, ':');) before I JSON.parse(messageData) it manually and use it (e.g. console.log( msgCallback['message'] );).

This whole thing seems really counter-intuitive to me, both the differences between the parent's and the contentWindow's (child's) messageCallback(), and the fact that, as is, I can use JSON only in one direction and a : would break any message from parent to the child.

Did I just implement the child iframe's messageCallback() wrong? I find the documentation on this really, really scarce and sketchy. I wouldn't be surprised if I just didn't use it correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions