admin管理员组文章数量:1417720
So I was messing around with the Html5 PostMessage sample at Html5 Demos and I created a sample jsfiddle to see if I understood how it worked together.
The demo makes use of document.getElementById(...)
which I thought could be replaced with the jQuery selector $("#...")
, but I got stuck on the because the returned object from the jQuery select does not have access to contentWindow
while document.getElementById(...)
does.
document.getElementById("frame1").contentWindow.postMessage("Hello from another domain", ""); // works
$("#frame1").contentWindow.postMessage("Hello from another domain", ""); // no dice
I'm not entirely well versed in jQuery to know which of the many methods to call on the results object from the selector to get back to the result I would see from document.getElementById(...)
.
So I was messing around with the Html5 PostMessage sample at Html5 Demos and I created a sample jsfiddle to see if I understood how it worked together.
The demo makes use of document.getElementById(...)
which I thought could be replaced with the jQuery selector $("#...")
, but I got stuck on the because the returned object from the jQuery select does not have access to contentWindow
while document.getElementById(...)
does.
document.getElementById("frame1").contentWindow.postMessage("Hello from another domain", "http://dl.dropbox."); // works
$("#frame1").contentWindow.postMessage("Hello from another domain", "http://dl.dropbox."); // no dice
I'm not entirely well versed in jQuery to know which of the many methods to call on the results object from the selector to get back to the result I would see from document.getElementById(...)
.
1 Answer
Reset to default 7$("#frame1") // This a jQuery object that encapsulate the DOM element.
$("#frame1")[0] // this is the DOM element.
//Or
$("#frame1").get(0) // this is the DOM element.
Full code:
$("#frame1")[0].contentWindow.postMessage("Hello from another domain", "http://dl.dropbox."); // DICE!
Updated Fiddle
But I find it awkward to use jQuery to select by id
then extract the DOM element out of it, and not using jQuery at all. what's wrong with document.getElementById
? those 15 extra chars?
本文标签: javascriptHtml5 postMessage using jQuerybut not jQuerypostMessage scriptStack Overflow
版权声明:本文标题:javascript - Html5 postMessage using jQuery, but not jQuery-postMessage script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745272193a2650960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论