Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery function to open link in new window

I'm trying to find a plugin or simple script to open a file in a popup window by clicking on a button. This used to work, but with all the jQuery updates (even with the migration file), this no longer works.

I found this, but this opens the popup and also redirects to the file url:

$(document).ready(function() {
$('.popup').click(function(event) {
    window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
 });
});

Any way to get a simple popup? It needs to have scrollbars, preferably resizable. I've seen lots of posts for modal boxes, but that does not accomplish what I need. The popup box has it's own design and there is more content than would be suitable for a modal.

I also want to avoid adding any extra markup. It makes the most sense to just add a class, like the example above.

like image 914
jenhan Avatar asked May 15 '13 16:05

jenhan


2 Answers

Try this,

$('.popup').click(function(event) {
    event.preventDefault();
    window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
});

You have to include jQuery reference to work this, here is the working sampe http://jsfiddle.net/a7qJt/

like image 157
Chamika Sandamal Avatar answered Oct 21 '22 04:10

Chamika Sandamal


Button click event only.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                $("#btnext").click(function () {                    
                    window.open("HTMLPage.htm", "PopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
                });
            });
</script>

like image 24
Murali P Avatar answered Oct 21 '22 04:10

Murali P