按下按钮,在php中打开一个新页面

时间:2011-10-23 10:47:00

标签: php javascript html

我希望在按下按钮时打开新页面。到目前为止,这是我的代码:

<input name="newThread" type="button" value="New Discussion" onclick="window.open('Political/Thread/thread_insert.php')"/>

然而,它失败了..我认为路径不正确,但我不知道为什么......因为它是正确的目录路径...

7 个答案:

答案 0 :(得分:8)

这将打开一个新的标签/窗口(取决于用户的设置):

<a class="button" href="Political/Thread/thread_insert.php" target="_blank">New Discussion</a>

要使这个“按钮”:

a.button {
    border: 1px solid #808080;
    background: #a0a0a0;
    display: inline-block;
    padding: 5px;
}

答案 1 :(得分:6)

您的代码是正确的(有效和功能),您的问题是您的路径。

请记住,页面位置是Web服务器内的页面,并且是相对于当前页面位置的页面。

因此,如果您的网络服务器根目录是c:\wamp\www,则网址test/test.php将查找c:\wamp\www\test\test.php的真实网页。但是,编码到已存在于子目录中的页面的相同地址将是相对的,除非它以/开头 因此,从上面示例中的test / test.php页面,test/test.php的链接将变为/test/test/test.php(实际路径为c:\wamp\www\test\test\test.php

如果您从某个地方复制了其他页面的链接,这可能就是问题

答案 2 :(得分:2)

尝试以下代码,

<INPUT type="button" value="Click" onClick="window.open('Political/Thread/thread_insert.php','windowname',' width=400,height=200')"> 

答案 3 :(得分:1)

试试这个:

<form action="Political/Thread/thread_insert.php" target="_blank" action="post">
<input name="newThread" type="submit" value="New Discussion" />
</form>

经过测试和工作。如果需要,可以将操作留空。

<form action="Political/Thread/thread_insert.php" target="_blank" action="">
<button>New Discussion</button>
</form>

但正如其他一个答案中所说的那样,你最好使用链接并将其设置为按钮。使用javascript或制作表单来获得相同的结果只是更多的工作而且......很糟糕。

答案 4 :(得分:1)

使用此

 <a href="../Myfolder/yourfile.html" type="button" class="btn btn-default subs-btn">Join</a>

类=“BTN btn是按钮的样式类。

如果你想直接链接到文件,而不必进入外部文件夹:

<a href="yourfile.html" type="button" class="btn btn-default subs-btn">Join</a>

我希望这会有所帮助

答案 5 :(得分:0)

将以下属性添加到元素,它看起来与按钮

完全相同

为链接禁用文字修饰以获得更好的效果

align-items: flex-start;
text-align: center;
cursor: default;
box-sizing: border-box;
padding: 2px 6px 3px;
border-width: 2px;
border-style: outset;
border-image: initial;
-webkit-appearance: push-button;
-webkit-user-select: none;
white-space: pre;
text-rendering: auto;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
margin: 0em 0em 0em 0em;
font: 13.3333px Arial;

我知道现在为时已晚,但我会把它放在寻找相同答案的其他人身上

答案 6 :(得分:0)

if(isset($_POST['myButtonName'])){
  header("Location:newPage.php");
  exit();
}

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
   <button style="margin-left:5px;" type="submit" class="btn btn-primary" name="myButtonName">Open</button>
</form>