これがシナリオです。fancyboxのiframeウィンドウを開くボタンのあるページがあります。iframeコンテンツ内には、を使用して新しいウィンドウで開くリンクがありますtarget="_blank"
。クリックしてjavascript関数をトリガーし、新しいウィンドウを開くだけでなく、fancyboxウィンドウを閉じたいと思います。
jqueryを使用して、呼び出す単純なクリック関数をバインドしましたparent.$.fancybox.close();
が、これはクリックをブラウザーに戻さず、新しいウィンドウでリンクを起動します。
99%の確率でブロックされるため、使用したくありませwindow.open
ん。デフォルトの動作が発生する必要があります。
通常の動作を実行させながら、閉じる関数onclickを呼び出すにはどうすればよいですか?
編集
コードの追加:
fancyboxiframeを開くページ。
<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>
これで、このコードはiframefancyboxウィンドウ内のcontent.aspページにあります
<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>