[英]accessing parent contents from inside iframe(on the same server machine) jquery working in firefox and IE but not in chrome
I am developing a music site , site contains a parent page with an iframe and a player. 我正在开发一个音乐网站,该网站包含一个带有iframe和播放器的父页面。 when menu is click the src of iframe is change depending on menu item clicked.In one page iframe contains music items. 单击菜单时,iframe的src会根据单击的菜单项而变化。在一个页面中,iframe包含音乐项目。 When a music is clicked inside iframe, i want to add that music in the playlist(contains in the parent). 当在iframe中单击音乐时,我想将该音乐添加到播放列表中(包含在父级中)。 My jQuery code is working in Firefox and Internet Explorer but in chrome. 我的jQuery代码在Firefox和Internet Explorer中可用,但在chrome中可用。 it gives an error below.. 它在下面给出一个错误。
Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". 未捕获到的SecurityError:阻止了源为“ null”的帧访问源为“ null”的帧。 Protocols, domains, and ports must match. 协议,域和端口必须匹配。 ... ...
here is my code 这是我的代码
$('span[name=add]').click(function(){
var song = $(this).attr("song");
var cover = $(this).attr("cover");
var artist = $(this).attr("artist");
window.parent.$('#playlist').prepend('<li song="'+song+'" cover="'+cover+'"artist="'+artist+'">'+song+'</li>');
window.parent.$('#playlist').trigger('change');
});
Pretty sure this is to stop phishing. 可以肯定的是,这将阻止网络钓鱼。
I haven't done this to manipulate DOM before, but when I bumped into this error, I found that this pattern worked. 我之前没有做过操作DOM的操作,但是当我遇到此错误时,我发现此模式有效。
Haven't tested this exact code, just for example. 尚未测试此确切的代码,例如。
Parent 父级
window.newHtml = "";
window.setHtml = function() {
$('#someElement').html(window.newHtml);
};
Iframe iframe
newHtml = "<p>yo!</p>";
setHtml();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.