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


Opening a new page in php on a button press

我想在按下按钮时打开一个新页面。下面是我到目前为止的代码:

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

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

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

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

设置为"a button":

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

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

请记住,页面位置是web服务器中相对于当前页面位置的页面。

因此,如果您的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)

如果您从其他页面复制了链接,这可能是问题所在

试试下面的代码,

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

试试这个:

<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或制作表单来实现相同的结果只是更多的工作和好……坏。

使用

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

class = " btnBTN是按钮的样式类。

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

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

希望对大家有所帮助

将下面的属性添加到元素中,它将看起来和按钮完全一样

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

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;

我知道这已经太迟了,但是我把它放在了其他正在寻找同样答案的人

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>