Open a new popup window and post data to it

喜你入骨 提交于 2019-11-29 14:42:18

问题


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');
}

回答1:


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>


来源:https://stackoverflow.com/questions/13657362/open-a-new-popup-window-and-post-data-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!