Hey All,

I'm trying to find out if there is a way to use PHP to open a new browser window and then write to it? Kinda like when you click on a link that runs a javascript to open and write to a new window so the link shows up in a new window, but not the simple 'target=_blank' of the <a> tag.

Thanks in advance,
Trevor

    tdawg wrote:

    Hey All,

    I'm trying to find out if there is a way to use PHP to open a new browser window and then write to it? Kinda like when you click on a link that runs a javascript to open and write to a new window so the link shows up in a new window, but not the simple 'target=_blank' of the <a> tag.

    Thanks in advance,
    Trevor

    Jscript = client side
    PHP = server side

    No jscript equivalent in PHP

      <?php
      echo '<html><script language="javascript"> window.open("page.html"); </script></html>';
      ?>

      although i do not understand the logic behind your question, i believe that would be a suitable solution.

        xxdrossxx wrote:
        <?php
        echo '<html><script language="javascript"> window.open("page.html"); </script></html>';
        ?>

        although i do not understand the logic behind your question, i believe that would be a suitable solution.

        You still used javascript... which he is trying to avoid...

        My first response accurately answers and explains (in a very brief sense) why there isnt a PHP solution

          tekky wrote:

          You still used javascript... which he is trying to avoid...

          My first response accurately answers and explains (in a very brief sense) why there isnt a PHP solution

          but he said "Kinda like when you click on a link that runs a javascript to open", so i kind of got the idea that he wanted both. i dunno.

            "is there a way to use PHP..." This is stating how he wants to solve the problem
            "kinda like when you click a link that runs javascript to open a new window and write to it..." this states an example of the problem

            😉

              I was just clarifying his statement so you'd understand the question (it's a very common question that he probably didn't search for either)

                Funny to see you two going at it 😃

                In any case, tekky is right, that's still using JS. PHP cannot open new windows, because it is client-side. You will have to use JavaScript.

                  Thanks everyone. What I've come up with at this point is messy, so I guess I'll rethink my javascript stuff and forget about doing it completely with PHP.

                    Allright then!

                    Please mark this resolved!

                      Depending on your needs HTML also has a means of doing this:

                      <a href="mytarget.html" target="_new">Click here to open a new window</a>

                      There is no means of doing this not only with PHP but with any server-side solution because of scope. You are executing code on the server end which cannot directly affect your client-side settings since the HTML deliverable that would affect your client-side settings has not yet been delivered by the web server. Thus, as others indicated, there is no way PHP, or any other server-side language, could accomplish this, and you are then forced to use HTML and/or Javascript (if you want a more globally-acceptable client-based solution, use my example above)

                      Phil

                        ppowell wrote:

                        .....(if you want a more globally-acceptable client-based solution, use my example above)

                        Phil

                        isnt the correct attribute value "_blank" ?

                          "_new" works as well. Try it.

                          Phil

                            The predefined targets are:
                            self

                            parent

                            top

                            blank

                            _blank ALWAYS opens a blank page.

                            Any other target (e.g., new), opens a new window identified by the target tag. Any additional hrefs with target = new will send content to that window. Means:
                            Click a target=new href 1st time: open new window
                            Click 2nd time: content sent to the open '
                            new' window

                            Since there is no 'focus()' equivalent, the window '_new' may well be hidden, and the user's perception may be that the link "doesn't work".

                            examples

                            Using _blank, opens 2 windows.
                            <a href=http://dontworry.org target=_blank>Dontworry in _blank window</a><BR>
                            <a href=http://anahataheartyoga.com target=_blank>Anahata yoga in _blank  window:</a><BR>
                            
                            Using _new, opens 1 window:
                            
                            <a href=http://dontworry.org target=_new>Dontworry in _new window</a><BR>
                            <a href=http://anahataheartyoga.com target=_new >Anahata yoga in _new window</a><BR> (remember that this window may have been hidden)

                            window</a><BR> (remember that this window may have been hidden)

                              Yes, however, "_blank" is the standard all the way back from HTML 4.1

                              Edit: nemo stuck in his post before mine, and made it sound/explain better!! 🙁

                                LoganK wrote:

                                Yes, however, "_blank" is the standard all the way back from HTML 4.1

                                Edit: nemo stuck in his post before mine, and made it sound/explain better!! 🙁

                                Nemo makes it sound like _Blank opens a blank window... its always opened a new window with the HREF I put as the target inside it for me... maybe just an unclear explanation... shrug

                                  "TARGET" tells the browser where to send the server's output: to a named frame or window, or to a frame by reference (self, parent, top), or to an as yet unopened window (blank). Using _blank creates a new window and pipes the output to that target.

                                  Using ANY OTHER than the four predefined elements pipes the output to the frame or window named as a target.

                                  If the target doesn't yet exist, it is created.

                                    Write a Reply...