创建PHP表单以加载URL

时间:2012-08-04 17:43:05

标签: php html forms

我希望我的表单能够加载网页。我想将html文本框转换为地址栏。就像我将URL写入其中一样,它在同一个窗口中加载网页。 我目前的HTML代码是:

<html>
<body>
<title>BlogSoc Browser</title>
<h1 style="font-family:verdana;font-size:50px;color:#000000;text-align:center;">Address Bar</h1>
<center><form method="GET" action="/load.php"><input type="text" name="url" value="http://" /><input type="submit" value="Go" name="submit" /></form></center>
</body>
</html>

看起来像这样:(无法发布图片) 或者你可以打开http://blogsoc.org/load 请告诉我相应的load.php代码。提前谢谢。

2 个答案:

答案 0 :(得分:2)

<?php
    header("Location: " . $_GET['url']);
?>

应该是你需要的。

答案 1 :(得分:0)

使用客户端脚本:

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
        $('#myform').submit(function(){ //when form is submitted..
            window.location = $('#url').val(); //..get url from the textbox and load that url
            return false; // prevent the form from being submitted
        });
    });
  </script>
</head>

<body>
  <form id="myform">
    <input type="text" id="url" value="http://" />
    <input type="submit" id="submit" value="Submit" />
  </form>
</body>

</html>

我使用了jQuery。供参考:https://developer.mozilla.org/en-US/docs/DOM/window.location