Reputation: 5316
Is there any way to open a new window or new tab using PHP without using JavaScript.
Upvotes: 4
Views: 6502
Reputation: 209
This answer is dedicated to the How to call a JavaScript function from PHP? thread; you can execute this block of code:
<?php
echo "<script> window.open(\"about:blank\"); </script>";
?>
Hopefully this helps!
Upvotes: -1
Reputation: 490173
Nope, a window can only be opening by adding target="_blank"
attribute (invalid in Strict (X)HTML, but valid in HTML5) or using JavaSript's window.open(url '_blank')
.
PHP runs server side - therefore it can generate the HTML or JavaScript, but it can't directly interact with the client.
Upvotes: 12
Reputation: 54358
PHP is server-side, as everyone states, however you can add a target="_blank"
attribute to your form tag. This doesn't perform any work server side, but does let you submit the form to a new window to be processed on the server.
A neat trick, but 1) deprecated in HTML Strict and 2) rarely useful.
Upvotes: 1
Reputation: 19466
PHP is a server-side language, it's what produces all the code you see on a page when you choose View Source. PHP cannot affect the client on its own, it needs to do it through a language such as JavaScript.
Upvotes: 1
Reputation: 1252
No. PHP is a server-side language, meaning that it is completely done with its work before the browser has even started rendering the page. You need to use Javascript.
Upvotes: 3
Reputation: 816364
Short answer: No.
PHP is a server side language (at least in the context of web development). It has absolutely no control over the client side, i.e. the browser.
Upvotes: 6