Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new popup window and post data to it

I'm using jQuery to open a popup and I'd like to send it data using the post method when it opens. Can anyone help me, thanks in advance.

I am currently passing the data using the get method so the data is a part in url, but I don't want the data to be visible in the url.

function openWindow(){

    var name = $('#name').val();

    var url = 'popup_window.php?name='+name;
    window.open(
        url,
        'popUpWindow',
        'height=400,     \
         width=650,      \
         left=300,       \
         top=100,        \
         resizable=yes,  \
         scrollbars=yes, \
         toolbar=yes,    \
         menubar=no,     \
         location=no,    \
         directories=no, \
         status=yes');
}
like image 526
Pramod Avatar asked Dec 01 '12 07:12

Pramod


1 Answers

This is based on the answer in How to open popup and populate it with data from parent window?

var newpage;
function openWindow() {
    $.post('popup_window.php', {name: $('#name').val()}, function(result) {
        newpage = result;
        window.open('Popup.html', 'popUpWindow','height=400, width=650, left=300, top=100, resizable=yes, scrollbars=yes, toolbar=yes, menubar=no, location=no, directories=no, status=yes');
    });
}

Popup.html should contain:

<script type="text/javascript">
    if(window.opener && !window.opener.closed) {
        document.write(window.opener.newpage);
    }
</script>
like image 170
Barmar Avatar answered Sep 20 '22 23:09

Barmar