IBRAHIM
IBRAHIM

Reputation: 11

Open a window behind the current window using Javascript/jQuery in php site

I want to open a window by Onclick of any element/links of my site, but I want to open it behind the current window, or when the new window opens it should minimize itself. I have made a function but it actually did not work

<?php if(!empty($directlink)){ ?>
<script type="text/javascript">
    $(document).ready(function() {
        var ec = "<?php echo $directlink; ?>";
        $("head").append('<link rel="preconnect dns-prefetch" href="' + ec + '">');
        $("body").one("click", function() {
            window.open(ec, "_blank", "");
        });
    });
</script>
<?php } ?>

Upvotes: 1

Views: 42

Answers (1)

Ninja Work
Ninja Work

Reputation: 624

This will work.

<?php if(!empty($directlink)){ ?>
<script type="text/javascript">
    $(document).ready(function() {
        var ec = "<?php echo $directlink; ?>";
        $("body").on("click", function() {
            window.open(ec, "", "width=300,height=300");
        });
    });
</script>
<?php } ?>

Upvotes: 0

Related Questions