4

Is there any way to open a new window or new tab using PHP without using JavaScript.

alex
  • 460,746
  • 196
  • 858
  • 974
Warrior
  • 4,848
  • 11
  • 58
  • 85

8 Answers8

12

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.

alex
  • 460,746
  • 196
  • 858
  • 974
  • the `target` attribute *is* valid in XHTML, so long as you use the Transitional doctype. Similarly, it's invalid in HTML if you're using the Strict doctype – Gareth Sep 21 '10 at 07:18
  • @Gareth Thanks will make an amendment. – alex Sep 21 '10 at 07:37
6

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.

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
3

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.

ashicus
  • 1,232
  • 10
  • 12
1

No, there is not.

hsz
  • 143,040
  • 58
  • 252
  • 308
1

No, PHP is server-side scripting

Bulan
  • 663
  • 1
  • 8
  • 24
1

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.

kba
  • 19,080
  • 5
  • 59
  • 87
1

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.

Tim M.
  • 52,666
  • 12
  • 118
  • 157
  • 1
    The only people that think that is useful are naive clients that think it will keep users on *their* website (there are a few defensible exceptions, however). +1 for *rarely useful*. – alex Sep 21 '10 at 08:50
-1

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!

Community
  • 1
  • 1
Obinna Nwakwue
  • 210
  • 4
  • 16