简体   繁体   中英

Opening modal in new Window using javascript or php

I'm trying to load a modal when link is clicked in a new tab and redirect my current page to another link. Something like what retailmenot does when you click a coupon. here is my code:

<div onClick="myFunction()">
    <a href="<?=site_url();?>deal/coupon_detail/<?=$row->deal_id;?>" class="get-code" data-toggle="modal" data-target="#copy_code<?=$i;?>" id="myModal">
        <?php echo $_SESSION['LANG']['lbl_home_get_code_text'];?>
    </a>
 </div>  
<script>
    function myFunction() {
        var newWindow= window.open("<?=site_url();?>",'_blank');
        $(newWindow).load(function() {
            newWindow.location=document.getElementById('myModal').href;
        });                          
        window.open("<?=site_url();?>deal/deal_exitclick_id/<?=$row->store_id;?>/<?=$row->deal_id;?>",'_self');    
    }
</script>

and the modal I'm trying to open is in an other classes:

<div id="myModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
  </div>
  <div class="modal-body copycode">
    <h4>Here's your Coupon Code</h4>
    <p>Paste this code at checkout when you are done shopping.</p>
    <span class="get-code" id="voucher_code_<?=$coupon->deal_id?>_get"><?=$coupon->voucher_code;?></span>
    <p><a class="copy-code" target="_blank" id="<?=$coupon->deal_id?>" href="<?=site_url();?>deal/deal_exitclick_id/<?=$store->store_id;?>/<?=$coupon->deal_id;?>">Copy Code</a>
    </p>
    <a target="_blank" href="<?=site_url();?>deal/deal_exitclick_id/<?=$store->store_id;?>/<?=$coupon->deal_id;?>">Click here to go to <?=$store->name;?> >>></a>
  </div>
</div>

You can open a popup window opening a file:

<a href="#" onclick="window.open('your/file/path','', 'width=200, height=100')">Click here</a>
<a href="#" onClick='window.open("", "", "width=200, height=100")'>Click here</a>

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM