-1

我有以下 PHP 代码

<?php
$q = rawurlencode($_POST["name"]); // input from textbox 1
$ft = $_POST["ftype"]; //input from textbox 2

当用户单击按钮时,我想http://www.example.com/$ft%20$q在新选项卡中打开。这可能吗?

我已经试过了curl_init

$h = curl_init("http://www.example.com/$ft%20$q");
curl_exec($h);

但这并没有达到预期的效果。

有人可以解释在用户浏览器中打开新标签的正确方法吗?

4

4 回答 4

1

如果您有 POST 数据,那么您在网站上有一些表格,对吗?然后你可以像这样在新标签中打开它:

HTML

<form id="form1" action="http://www.example.com/$ft%20$q" method="post" target="_blank">
   <input type="text" id="name" name="name" />
   <input type="text" id="ftype" name="ftype" />
   //submit
</form>

查询

 <script type="text/javascript">
   var ft = "";
   var q = "";

   function createURL() {
       $("#form1").attr("action", "http://www.example.com/" + ft + "%20" + q);
   }

   $(document).ready(function () {
       $("#name").keyup(function () { 
           q = $("#name").val();
           createURL();
       });

       $("#ftype").keyup(function () { 
           ft = $("#ftype").val();
           createURL();
       });
   });
</script>

以及 jsfiddle 的工作代码,其中演示了 url 更改。http://jsfiddle.net/Driveash/7p6BN/

于 2013-11-14T18:47:20.443 回答
0

You must do this functionality in your HTML using the target attribute on your anchor tag with the _blank value, like this

<a href="http://google.com" target="_blank">Click Me!</a>
于 2013-11-14T18:42:16.520 回答
0

You can't open tabs in PHP as PHP is server side code, not client side.

Read this answer for the explanation of the difference:

https://softwareengineering.stackexchange.com/a/171210

于 2013-11-14T18:42:18.313 回答
-1

This might not be the best way, but if you are on a page with strictly PHP, you could always echo out some basic JavaScipt and just inject the variables.

echo ("<script>window.open(\"" . $link . "\");</script");
于 2013-11-14T18:41:50.390 回答