在父域(相同的域)中单击iframe打开事件内部吗? [英] Click inside iframe open event in parent (same domains)?

查看:89
本文介绍了在父域(相同的域)中单击iframe打开事件内部吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用.slideToggle从我的日历(在iframe中)打开事件详细信息,我的代码是:

I want to use .slideToggle to open event details from my calendar (in iframe) My code is:

<div id="clickme"><iframe id="frame" src="index.php?option=com_jevents&view=month&task=month.calendar&template=ja_purity" mce_src="index.php?option=com_jevents&view=month&task=month.calendar&template=ja_purity">Your browser does not support iframes.</iframe></div>

<div id="book" style="display:none;"><iframe name="details" scrolling="no" frameborder="0"></iframe></div>
<script>
$('#clickme').click(function() {
  $('#book').slideToggle('slow', function() {
    // Animation complete.
  });
});
</script>

您可以在此处查看其工作方式: wisko.pl 现在,仅当我单击iframe边框时,幻灯片才能工作.我想在日历中单击事件时将其打开.是否有可能?如何使用.click函数检查iframe中的div?

You can see how it works here: wisko.pl Now slide work only when i click iframe border. I'd like it to open when i click on event in calendar. Is it possible? How can i use .click function to check divs inside iframe?

谢谢.仍然不起作用.难道我做错了什么?我的主要文件有:

Thank you. Still doesn't work. Am I doing something wrong? My main document has:

<script>
function showevent(){
$('#book').slideToggle('slow', function() {
    // Animation complete.
  });
}
</script>

在iframe中,我输入:

In Iframe i put:

<script>
$('#eventstyle').click(function() {
document.parent.showevent();
}
</script>

推荐答案

在主文档中:

function showevent(){
$('#book').slideToggle('slow', function() {
    // Animation complete.
  });
}

在iframe内部:

window.parent.showevent();

在iframe中运行此命令将导致该函数运行.而且您必须在iframe中捕获click事件-否则就无法这样做.

running this inside iframe will cause the function to run. And you have to catch the click event inside the iframe - you can't otherwise.

1.我的坏:我把document.parent放在这里而不是window.parent-现在修复 2.不好的地方:使用jquery将事物分配给单击事件时,必须确保这些事物已经存在.所有的jquery代码都应该包装在$(document).ready(function(){/*your code here*/});中,这就是为什么它没有机会为您工作的原因.

edit: 1. My bad: i put document.parent here instead of window.parent - fixed now 2. Your bad: when you use jquery to assign click events to things, you have to be sure these things already exist. all jquery code should be wrapped in $(document).ready(function(){/*your code here*/}); That's why it had no chance of working for you.

这篇关于在父域(相同的域)中单击iframe打开事件内部吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆