dtr84664 2014-07-25 07:55 采纳率: 100%
浏览 115
已采纳

HTML标签打开新窗口并发送POST值[重复]

This question already has an answer here:

I Want to open new window, And send to php file POST value.

Like

<a href = 'URL.php' target = '_blank'> Tish is link </a>

How to send POST value?

Edit : I already try this

<form target='_blank' method='POST' action='code.php'>
<input type = 'hidden' name='function_code' value='$code'>
<button id='submit_button' type = 'submit' value='$code'>$code</button>
</form>

But target=_blank opened new tab, not a pop-up(new window) I want to open 'New window & pop-up', Send Post value When i click button.

Solved like this

<form action='#' method='post' name='fdata' id='fdata'>
<input type='hidden' name='code' value='$code'>
<input type='button' name='btn' value='$code' onclick='window_open();'>
</form>

function window_open()
{
    window.open("about:blank","window_name","width=640,height=480,scrollbars=yes");
    document.fdata.target = "window_name";
    document.fdata.method = "post";
    document.fdata.action = "code.php";
    document.fdata.submit();
}

Thank you so much!

</div>
  • 写回答

1条回答 默认 最新

  • doutu4335 2014-07-25 08:01
    关注

    This is natively not possible.

    You can however cheat a little and create a form to submit your data from there. It might be the easiest to use a button to submit the form, and restyle it to look like a link (see this question).

    <form action="#" method="post" target="_blank">
        <input type="hidden" name="name" value="user3273401">
        <input type="hidden" name="text" value="I wanna do this!">
        <button type="submit" value="Tish is link">Tish is link</button>
    </form>
    

    This will send the data to a new tab with the POST method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件