ต่อไปนี้เป็นสถานการณ์ ฉันมีหน้าเว็บที่มีปุ่มสำหรับเปิดหน้าต่าง iframe ของ fancybox ภายในเนื้อหา iframe จะมีลิงก์ที่จะเปิดในหน้าต่างใหม่โดยใช้ target="_blank"
ฉันต้องการให้คลิกเพื่อเรียกใช้ฟังก์ชันจาวาสคริปต์เพื่อปิดหน้าต่าง fancybox รวมถึงเปิดหน้าต่างใหม่
การใช้ jquery ฉันได้ผูกฟังก์ชันการคลิกง่ายๆ ที่เรียก parent.$.fancybox.close();
แต่สิ่งนี้จะไม่ส่งคืนการคลิกกลับไปยังเบราว์เซอร์เพื่อเริ่มลิงก์ในหน้าต่างใหม่
ฉันไม่ต้องการใช้ window.open
เนื่องจากถูกบล็อก 99% ฉันแค่ต้องการให้พฤติกรรมเริ่มต้นเกิดขึ้น
ฉันจะเรียกใช้ฟังก์ชันปิด onclick ในขณะที่ปล่อยให้พฤติกรรมปกติเกิดขึ้นได้อย่างไร
แก้ไข
การเพิ่มรหัส:
เพจที่เปิด iframe ของ fancybox
<a href="http://something.com" id="OpenIframeLink">open fancybox</a>
<script>
$("#OpenIframeLink").fancybox({
'padding': '20',
'width': 450,
'height': 550,
'scrolling': 'no',
'type': 'iframe',
'href': '/content.asp?url=' + encodeURIComponent($("#OpenIframeLink").attr('href')),
'showCloseButton': false
});
</script>
ตอนนี้โค้ดนี้อยู่ในหน้า content.asp ภายในหน้าต่าง iframe fancybox
<div id="message">
<a href="http://something.com" target="_blank">click me</a>
</div>
<script type="text/javascript">
$('#message a').click(function() {
parent.$.fancybox.close();
//now it should open the new window as a standard default click
//as if this function wasn't bound to the click
});
</script>