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

在php中按一个按钮打开一个新页面,php,javascript,html,Php,Javascript,Html,我想在按下按钮时打开一个新页面。以下是我目前的代码: <input name="newThread" type="button" value="New Discussion" onclick="window.open('Political/Thread/thread_insert.php')"/> 但是,它失败了,…我认为路径不正确,但我不知道为什么..因为它是正确的目录路径…这将打开一个新的选项卡/窗口(取决于用户的设置): 试试下面的代码 <INPUT type="b

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

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


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

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

试试下面的代码

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

您的代码正确(有效且功能正常),问题在于您的路径

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

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

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

请尝试以下操作:

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

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


新讨论
但正如在另一个答案中所说的,你最好使用一个链接,并将其样式设置为按钮。使用javascript或制作表单来获得相同的结果只是需要更多的工作,而且。。。坏。

用这个

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

class=“btn btn是按钮的样式类

如果您希望直接链接到该文件,而不必进入外部文件夹:

<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($\u POST['myButtonName')){
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>
标题(“位置:newPage.php”); 退出(); }
我说过,我希望它是一个按钮。我也想过这样做。但我更希望它看起来像一个按钮。我发现了一些有用的东西:@Matrix:Tough。它不是一个按钮。它是一个链接,因为它打开了一个新页面。链接应该用
标记。你说的“看起来像一个按钮”到底是什么意思“?新页面的打开对我很有用。如果您没有到达正确的页面,那么您的路径肯定是错误的。也许尝试一条绝对的道路我怎么会这样呢。。这是绝对路径..:(你确定吗?这不应该是相关的。内部服务器设置对用户对URL的感知没有影响。我只包括他们的声明,因为原始海报上说路径是正确的目录路径,而且似乎问题与路径有关,原始海报可能会混淆目录p。)ath有一个web地址路径。再读一遍,你只是用一种奇怪的方式陈述了一些事情。真正的路径位置是一个实现细节。我们只关心web地址。但这一点本身是正确的。我认为你发现了问题。在设计每个文件的位置时,我需要小心重定向和包含谢谢你的链接,我使用了a href=“linkName.php”…它成功了。如果你在做任何事情,而不是为此使用链接,那么路径都是不正确的。你做错了。我只是提供了一个有效的答案,因为你希望有一个按钮,而不是你应该使用的按钮。@Matrix001:而不是javascriptWelcome,欢迎使用堆栈溢出!请不要只使用源代码回答。请尝试使用提供有关解决方案工作原理的详细说明。请参阅:。谢谢
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>