有没有什么好的工具,允许开发人员正确地调试窗口与
postMessage之间发送的消息?
或者也可以是Firebug的插件?
解决方法
FireBug
(as of 1.11 beta 1)支持monitorEvents().你可以这样做:
$("iframe").each(function(i,e) { console.log("Monitoring messages sent to: iframe(" + i + ")#" + $(this).attr("id")); monitorEvents(this.contentwindow,"message"); // Send a test message to this iframe this.contentwindow.postMessage("Hi iframe - " + i,"*"); }); console.log("Monitoring messages sent to window"); monitorEvents(window,"message"); // Send a test message to the window window.postMessage("Hi window","*");
(@Pierre:感谢提到feature request)
编辑:Also works in Chrome,虽然我尝试了上面的代码,我遇到一个安全性错误,document.domain值不一样,所以这两个实现的行为可能会有所不同.
更新:我有submitted a feature request的Chrome小组要求postMessage事件出现在时间轴.此外,我发现一个extension called JScript Tricks可以在页面加载时将任意JavaScript代码注入到页面中.您可以添加以下代码以在页面加载后监视事件.它工作得很好,尽管它可能会错过立即发生的事件(例如在上载之前,如果可能的话).
(function($) { var $window = $(window); $window.add("iframe").on("message",function(e) { console.log("Received messsage from " + e.originalEvent.origin + ",data = " + e.originalEvent.data); }); })(jQuery);
原文地址:https://www.jb51.cc/html5/168686.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。