I've this form:
<form id="form1" name="form1" method="post" action="http://gmail.com"
onsubmit="setTimeout(function () { window.location.reload(); }, 10)">
<div class="form-group">
<label for="email">E-mailadres</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<input type="submit" value="verzenden" class="btn btn- primary" />
</form>
I want that if someone clicks on the button, he/she will redirect to gmail.com I try target blank, but it doesn't work, does someone know a good manner to redirect with javascript or php?
EDIT: I want that if someone hit the button he/she will redirect to a new tab.
Try
<input type="button" value="verzenden" class="btn btn- primary" onclick="move_to_gmail();"/>
<script>
function move_to_gmail(){
window.location = 'http://www.gmail.com';
}
</script>
with PHP, you could use
header('Location: http://www.example.com/');
and with JavaScript, use
document.location.href="http://www.example.com";
I agree that this scenario is a bit strange as I have no idea what you're actually trying to accomplish but, if you just want to open gmail.com in a new window when the form is submitted, this should suffice:
<form onsubmit="window.open('http://gmail.com')">
<div class="form-group">
<label for="email">E-mailadres</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<input type="submit" value="verzenden" class="btn btn- primary" />
</form>
To open a new window (if it's really a new window or a new tab is decided by the browser, you can't influence this), use window.open() :
<form id="form1" name="form1" method="post" action="http://gmail.com"
onsubmit="window.open('http://gmail.com');return false;">
window.open('http://gmail.com');
opens gmail.com, return false;
cancels the submitting of the form. This won't send the data from the form to gmail.com! Demo: http://jsfiddle.net/30d6em13/
Without JavaScript use target="_blank"
<form id="form1" name="form1" method="post" target="_blank" action="http://gmail.com">
This will open http://gmail.com in a new window/tab. But this will send the data entered into the form to gmail.com! Demo: http://jsfiddle.net/30d6em13/1/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.