2017-04-11 26 views
0

這是我的代碼,單擊「提交」時我想重定向到另一個站點,但我找不到錯誤在哪裏。這是一個簡單的代碼,我知道這看起來有點「醜陋」,但我只是在測試。無法重定向html

<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t <meta charset="UTF-8"> 
 
\t <link href="paginaweb.css" rel="stylesheet" type="text/css"> 
 
\t <script type="text/javascript"> 
 
\t \t function redirect(){ 
 
    \t \t window.location.href("https://www.outlook.com"); 
 
    \t \t return(false); 
 
\t \t } 
 
\t \t </script> 
 
\t </head> 
 
\t 
 
\t \t <body class="container"> 
 
\t \t \t <div class="image"> </div>​ 
 
\t \t \t \t <div> 
 
\t \t \t \t \t <style> 
 
\t \t \t \t \t \t input[type=text] { 
 
\t \t  \t \t \t \t \t width: 100%; 
 
\t \t  \t \t \t \t padding: 12px 20px; 
 
\t \t  \t \t \t \t margin: 8px 0; 
 
\t \t  \t \t \t \t box-sizing: border-box; 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t </style> 
 
\t \t \t \t \t <label for="email"> 
 
\t \t \t \t \t <p class="fuente">Introduce tu email para conectarte a Internet.</p></label> 
 
\t \t \t \t \t <form onsubmit="redirect()"> 
 
\t \t \t \t \t \t <input type="email" placeholder="Your email..."> 
 
\t \t \t \t \t <input type="submit" id="submit" value="Submit"> 
 
\t \t \t \t \t </form> 
 
\t \t \t \t </div> 
 
\t \t \t </body> 
 
</html>

+0

爲什麼不直接設置'form'的'action'參數的網址是什麼? –

+0

你需要提交價值到其他網址或只是重定向? –

+0

'window.location.replace(「https://www.outlook.com」);'這個怎麼樣? –

回答

1

你應該可以用下面的代碼來實現這一目標:

<form method="post" action="newurl.com"> 
    <input name="email" type="email" placeholder="Your email..."> 
    <input type="submit" id="submit" value="Submit"> 
</form> 

只需設置表單操作並將表單數據發送到新的url。

+0

**它的工作。 TY!** –

+0

沒問題,請標記爲@BernatPedrolVozmediano :) –

0

回答自己:

爲了避免錯誤405,改變

<form method="post" action="newurl.com"> 

<form method="get" action="newurl.com">