简体   繁体   English

从iframe内部(在同一台服务器上)访问父级内容,但在Firefox和IE中却无法在chrome中使用

[英]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的操作,但是当我遇到此错误时,我发现此模式有效。

  1. Create function in parent window. 在父窗口中创建函数。
  2. Call function from iframe. 从iframe调用函数。

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.

相关问题 从iFrame更改父页面URL在IE中工作,但在Firefox和Chrome中不起作用 - Change parent page url from an iFrame works in IE but not in Firefox and Chrome 访问iFrame中的元素(例如,9,Chrome,Firefox) - Accessing elements in an iFrame (ie9, Chrome, Firefox) 从可在IE中运行但无法在Chrome或Firefox中运行的iframe获取价值 - Getting value from iframe working in IE but not Chrome or Firefox 具有iframe的FancyBox在Chrome中工作,但在IE或FireFox中不工作 - FancyBox with iframe working in Chrome but not working in IE or FireFox iframe onload调整大小可在Chrome中使用,但不能在IE或Firefox中使用 - Iframe onload resizing working in Chrome, but not IE or Firefox JavaScript调整大小iFrame - 在Firefox / IE中工作但不在Chrome中工作 - JavaScript Resize iFrame - working in Firefox/IE but not Chrome jQuery选项卡不适用于Firefox和chrome。 在IE 9上也可以使用 - Jquery Tab not working on Firefox and chrome. Same works on IE 9 jQuery的切换不能在Chrome中工作,但在IE和Firefox中工作 - jquery toggle not working in chrome but working in IE and firefox JQUERY自动完成功能可在chrome和firefox中使用,但不能在IE中使用 - JQUERY autocomplete working in chrome and firefox but not working in IE 在子框架中访问父框架中的父iframe元素只能在Firefox中运行,而不能在Chrome中运行 - Accessing parent iframe element in child frame works in Firefox and not in Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM