2015-08-27 107 views
3

我有一个链接,称为弹出视图名为class =“iframe”。 我计划在弹出窗口里面设置一个窗体,但是我的问题是我需要关闭那些弹出后点击提交然后我的原始页面,或者我弹出的背景会自己刷新它。 我的脚本:提交后关闭iframe

<script src="<?php echo base_url(); ?>template/popup/jquery.colorbox.js"></script> 
 
<script type="text/javascript"> 
 
var $ = jQuery.noConflict(); 
 
    $(document).ready(function(){ 
 
     //Examples of how to assign the Colorbox event to elements 
 
     $(".iframe").colorbox({iframe:true, width:"50%", height:"78%"}); 
 

 
     //Example of preserving a JavaScript event for inline calls. 
 
     $("#click").click(function(){ 
 
      $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here."); 
 
      return false; 
 
     }); 
 
    }); 
 
</script>
<a class='iframe' href="#">POP UP </a>

回答

0

使用window.open打开弹出式窗口,并将其保存到一个变量。这个变量将指向那个窗口对象。你可以稍后在这个变量上调用.close

var url = 'http://yourwebsite.com/subpage-within-your-website.html'; 
popup_window = window.open(url); 
popup_window.close(); 

注:由于对I帧JavaScript的安全限制,这只会工作,如果叫上属于同一个域的页面。我也写了一个jsFiddle,但它似乎已经启用了沙盒,从而阻止了iframe的访问。

This page有一个工作示例。 Source code

+0

亲爱的Ayrit,谢谢你,伙计,它已经帮了我一些忙,当我关上窗户时,怎么可以当前窗口是否自动刷新? – Mauliardiwinoto