簡體   English   中英

按下按鈕,在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 {
    border: 1px solid #808080;
    background: #a0a0a0;
    display: inline-block;
    padding: 5px;
}

你的代碼是正確的(有效和功能),你的問題是你的道路。

請記住,頁面位置是Web服務器內部的頁面,並且是相對於當前頁面位置的頁面。

因此,如果您的Web服務器根目錄是例如c:\\wamp\\www那么Web地址test/test.php將查找c:\\wamp\\www\\test\\test.php的真實頁面。 然而,除非它開始於一個子目錄編碼成一個頁面已經相同的地址將是相對/所以在上面的例子中的鏈接的網頁測試/ 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')"> 

用這個

 <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>

我希望這有幫助

嘗試這個:

<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或制作表單來實現相同的結果只是更多的工作,而且......糟糕。

將以下屬性添加到元素,它看起來與按鈕完全相同

禁用鏈接的文本修飾以獲得更好的效果

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM