小编chr*_*980的帖子

关于javascript postmessage到本地磁盘上的父HTML iframe

我正在开发一个涉及在iframe中托管网页的项目,而托管父iframe位于本地磁盘上的HTML文件中,比如c:\; 而内部托管的iframe在某些服务器上.这两个网页需要彼此进行邮寄消息.

父内容iframe(在本地磁盘上)将消息发送到内部框架没有问题,因为它知道内部iframe的域;

但是当内部iframe需要postmessage回到父iframe时,它需要提供本地磁盘上的父iframe的域.

我在内部HTML中尝试了以下内容,将postmessage邮寄到其父IFrame,该IFrame位于本地磁盘上:

*var messageToSend = {
                        jsonrpc: "2.0",
                        result: [result]
                    };
window.parent.postMessage(JSON.stringify(messageToSend), "file://");*
Run Code Online (Sandbox Code Playgroud)

// window.parent IFrame是本地磁盘上的HTML文件

但是当我尝试使用"file:"作为postmessage中的域回到父iframe时,我收到一个"无效参数"错误.

有人可以帮忙吗?"本地磁盘html"的域应该是什么?任何提示将受到高度赞赏.

干杯

javascript postmessage file local

3
推荐指数
1
解决办法
4271
查看次数

标签 统计

file ×1

javascript ×1

local ×1

postmessage ×1