簡體   English   中英

在外部窗口中從彈出窗口打開鏈接,然后關閉原始彈出窗口

[英]open the link from the popup window in an external window and then close the original popup window

我有一個需要從父窗口打開彈出窗口的要求。 我能夠成功做到這一點。

現在我想做的是-假設一個彈出窗口已打開,並且該彈出窗口中有一些鏈接,如果我嘗試單擊該鏈接,它將在新窗口中打開該鏈接,並且原始彈出窗口應關閉。

這是我的小提琴 在這個小提琴中,如果您單擊“應用”按鈕,它將打開一個正常工作的彈出窗口,但是如果您單擊該彈出窗口中的任何鏈接,則該鏈接會在同一彈出窗口中打開,這是我不想要的。 我想在新的外部窗口中打開該鏈接,並且原始彈出窗口應該關閉。

以下是JS代碼-

function open(url) {
    $('#blockdiv').fadeIn();
    $('#iframe').attr('src', url);
    $('#containerdiv').fadeIn();   
}

function close() {  
    $('#blockdiv').fadeOut();
    $('#containerdiv').fadeOut();  
}

$(document).ready(function() {
  $('ul').css({width: $('#containerdiv').width(),height:    $('#containerdiv').height()})
     $('#close').click( function() { close() })
     $('.JN_apply').click( function() { open($(this).data('url')); })

});

我在小提琴中給出的示例將打開www.ebay.com網站,但總的來說,這將是我的頁面,將作為彈出窗口打開。

有可能嗎? 如果是,有人可以幫我嗎?

更新的代碼:-

現在,我已經開始使用jQuery colorbox進行上述操作-

以下是我的父窗口代碼,它將打開彈出窗口-

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8'/>
        <title>Colorbox Examples</title>
        <style>
            body{font:12px/1.2 Verdana, sans-serif; padding:0 10px;}
            a:link, a:visited{text-decoration:none; color:#416CE5; border-bottom:1px solid #416CE5;}
            h2{font-size:13px; margin:15px 0 0 0;}
        </style>
        <link rel="stylesheet" href="C:\Users\rj\Downloads\colorbox-master\example4\colorbox.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script src="C:\Users\rj\Downloads\colorbox-master\jquery.colorbox.js"></script>
        <script>
            $(document).ready(function(){
                //Examples of how to assign the Colorbox event to elements
                $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});

            });
        </script>
    </head>
    <body>
        <h2>Other Content Types</h2>
        <p><a class='iframe' href="http://www.wikipedia.com">Outside Webpage (Iframe)</a></p>

        </body>
</html>

下面是我的彈出窗口代碼,其中包含一個鏈接,我需要通過關閉原始彈出窗口在新的外部窗口中打開以下鏈接:

<html>
<head>
  <title>Apply</title>
</head>
<body>

<script>
function getUrlParameters() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, 
        function(m,key,value) {
            vars[key] = value;
        });
    return vars;
}
var id = getUrlParameters()["ID"];    
var title = getUrlParameters()["Title"];    
var id = unescape(id);
var title = unescape(title);

var myJScript = document.createElement('script');

myJScript.setAttribute('type', 'Apply');
myJScript.setAttribute('data-companyId', '40');
myJScript.setAttribute('data-jobTitle', id );
myJScript.setAttribute('data-email', 'admin@domain.net');

document.body.appendChild(myJScript); 
</script>
<hr>

<input name="Apply Online" type="button" id="Apply Online" value="Apply Online" ONCLICK="window.location.href='some_url'">

</body>
</html>

現在,在單擊“在線申請”鏈接后應如何在這種情況下關閉彈出窗口,而“在線申請”鏈接應在新的外部窗口中打開? 我希望這個問題應該足夠清楚。

嘗試

<input name="Apply Online" type="button" id="Apply Online" value="Apply Online" ONCLICK="window.location.href='some_url';$.colorbox.close();">

要么

<input name="Apply Online" type="button" id="Apply Online" value="Apply Online" ONCLICK="window.location.href='some_url';parent.$.colorbox.close();">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM