jquery怎么在iframe中关闭colorbox--国外的贴子
luyued 发布于 2011-06-13 06:23 浏览 N 次i have a page manageGroup.php, where user can also add member to group. I used colorbox to show the addGroupMember.php. Now i need to close that colorbox once i have done submitting the form.
javascript i am using in manageGroup.php
The link i am using to open colorbox
g_id)?>">Add Member
the code in addGroupMember.php is like this:-
if($_POST['add']=="Go")
{
$gid = $_POST['id'];
$ii=0;
$insert = "INSERT INTO ".DBGMEMBER." (gm_g_id,gm_m_id) VALUES ";
foreach($_POST['gMember'] as $gMember)
{
if($ii==0)
{
$insert .= " ('".$gid."' , '".$gMember."')";
}
else
{
$insert .= " ,('".$gid."' , '".$gMember."')";
}
$ii++;
}
$db->execute($insert);// after this i want to close the colorbox
echo "";// code i used, but not working
}
8 Answers
active oldest votesFirst: Elaborate you question. The information you provided is some what shorthanded. There's no chance one could grip what you are doing. Also include some more sample code.
Only thing I could guess is that you trying to trigger the method in how it's written. Everything you add to the $.fn object is bound to all jQuery objects.
// doesn't work
$.fn.colorbox.close()
// proper way
$('idOfDomElement').colorbox.close()
hi fredrik, i have posted an elaborated description to my problem. but i didn't got your point of using $('idOfDomElement').colorbox.close(). – Ashish Rajan Jan 20 '10 at 13:54Could you please add the javascript code where you open the colorbox? – fredrik Jan 20 '10 at 14:09javascript code added – Ashish Rajan Jan 20 '10 at 14:56Should be something along the lines of: $(".iframe").colorbox.close(); or parent.$(".iframe").colorbox.close(); – fredrik Jan 20 '10 at 15:40
i got it done for me, a bit crazy way, anyways u can too give it a try.
Supposing your page in iframe as x.php having form named xyz
if($_post['submit']=='Submit')
{
//some php code here
if(success)
echo "";
else
{
//some error handling here;
}
}
?>
This one worked out perfectly for me and should work for you
parent.$.fn.colorbox.close()
I think the problem is that the colorbox belongs to the parent, not to the DOM in the iframe.
My guess is you'll need to call parent.[way to get the element or $.fn object].colorbox.close() or you'll need to add a function to the parent document and call parent.myCloseFunction()
10x. This way works great for me. – Dichev Feb 9 at 1:24I just tried to close colorbox from within the iframe but couldn`t get it to work. I used $('#closebox').colorbox.close() and without any luck.
Make sure that the page loaded within the iFrame includes all of the necessary references to the colorbox js, jQuery js and probably even the colorbox CSS just to be safe.
Then the parent close call should work: parent.$('.yourElement').colorbox.close();
just this
parent.$.colorbox.close()
seems to work for me!
I used it like this without even a reference to any JS in the file loaded into the iframe.
href="">close
this alone in a blank HTML file seems to work.
I did not manage to close the Colorbox with suggested solutions. I get parent undefined... So..
I found took a different approach:
Home document: (iframe: false) this will open the ajax_page in DIV in the same document
$(document).ready(function(){
$("#modalwindow").colorbox({
width:"800px",
height:"510px",
iframe:false,
href:"../ajax_page.php",
});
});
and in the ajax_page
$('#modalwindow').colorbox.close();
Hope this helps
引文来源 jquery - how to close colorbox within iframe? - Stack Overflow
- 07-01· 禁教唐诗算术能还幼儿快
- 07-01· 2011年06月17日
- 07-01· 唐诗宋词英译:李商隐 筹
- 07-01· 仿评《唐诗1000首》第186首
- 07-01· 没事干的时候背背唐诗吧
- 07-01· [转载]唐诗中“斜”字该读
- 07-01· 湖南醴陵瓷业转型升级
- 07-01· 奇瑞风云2两厢黑色|2010款
- 07-01· 摩根士丹利华鑫摩根士丹
- 07-01· 摩根士丹利华鑫近期优选
- 07-01· 中金投行部大摩出售中金
- 07-01· 摩根士丹利招聘6月2日【实
- 07-01· 营养防病圣典
- 07-01· 《博伽梵歌原意》之第十
- 07-01· [不错]斑斓圣典---减肥中常
- 07-01· 武乐圣典《太极武当》:武
- 07-01· 铁血英雄-现阶段战功牌兑
- 07-01· 2011年06月10日【原创】南歌
- 07-01· 【淘宝网信息】- 2010年的
- 07-01· 深圳品牌女装有哪些?