Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389

    Help please with php close window problem

    Hello

    I'm wondering if anyone can help me with a php/javascript problem I'm having?

    I've searched here and on google, but haven't been able to find what I'm looking for.

    Problem:

    I have a pop up window that runs a form and then when completed goes to a confirm page.
    On this confirm page, I want to add a close window link at the bottom, such as :
    PHP Code:
    <a href="javascript:window.close();"><small>Close This Window</small></a
    Currently I get this error:
    Parse error: parse error, unexpected T_STRING, expecting ',' or ';'

    How can I best add this to my code: (for example - which does not work!)
    PHP Code:
    echo "Click < a href="javascript:window.close();">here</a> to close this window."
    Or, is there a php method of closing a browser window??

    Thanx!!
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  2. #2
    Join Date
    Aug 2001
    Posts
    4,028
    I am no guru, but I think it's because of the middle quote:

    Do this:

    echo "Click < a href="javascript:window.close();\">here</a> to close this window.";

  3. #3
    Join Date
    May 2001
    Location
    Prince Edward Island
    Posts
    965
    Not sure if this will help or not.

    http://forums.devshed.com/archive/16/2002/10/1/44626
    [url]I got nothing/url]

    For clarity's sake, don't use "<ip address of hostname>" use the ACTUAL 32-bit numeric IP address of the machine.

  4. #4
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389
    Thanx Mekhu for the reply

    Nope... that returns the same error

    Any other ideas???
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  5. #5
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389
    Hi MikeM

    I'd already found that page and tried it, but either I didn't enter the info correctly into the php page or it didn't work.... but it still turns up the same error.

    Thanx for the reply though! Much appreciated
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  6. #6
    Join Date
    May 2001
    Location
    Prince Edward Island
    Posts
    965
    Maybe try calling a .js file instead??
    [url]I got nothing/url]

    For clarity's sake, don't use "<ip address of hostname>" use the ACTUAL 32-bit numeric IP address of the machine.

  7. #7
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389
    Hi

    ?? I don't think I understand?

    Call a js file from inside the .php file? or ....
    (apologies if I'm being a little thick here )
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  8. #8
    Join Date
    Jan 2003
    Location
    Glendale, Arizona, USA
    Posts
    165
    You have your code like:

    PHP Code:
    echo "Click <a href="javascript:window.close();">here</a> to close this window."
    PHP reads ECHO and the first quote, then sees the second quote following href= and expects the semi colon. So what you need to do is add a backslash to each quote so PHP doesn't read it as closing the echo. Such as:

    PHP Code:
    echo "Click <a href=\"javascript:window.close();\">here</a> to close this window."
    Or, to make it slightly simpler for you, you could do something like the following, where you will not have to worry about backslashes and etc:

    PHP Code:
    echo <<<END
    Click <a href="javascript:window.close();">here</a> to close this window.
    END; 

    Let me know if that fixes it.

  9. #9
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389
    Hi PUBH

    Thanx for the reply!

    That kind of worked It doesn't give me the parse error anymore... however, instead of closing the window it takes me to my error404 page.

    Feeling very blonde right now
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  10. #10
    Join Date
    Jan 2003
    Location
    Glendale, Arizona, USA
    Posts
    165
    Well it appears the errors from the PHP side are gone.

    I would assume your errors are resulting in your JavaScript, but unfortunately I am not very experienced with it. I will look it up real quick and see if I can figure it out for you...

  11. #11
    Join Date
    Jan 2003
    Location
    Glendale, Arizona, USA
    Posts
    165
    Your URL should look something like:

    Code:
    Click <a href="javascript:window.close();">here</a> to close this window.
    So in PHP, you will need to add echo, quotes, backslahes, ect (if needed). The space you have in your link (between JAVA and SCRIPT) would possibly be causing the error.

    Try it out.




    EDIT: In the above example there SHOULD NOT be a space between JAVA and SCRIPT, but for some reason when I post, or edit, it appears with no space in here, but when viewing, it adds a space. The below site shows how it should look (JavaScript-wise):

    http://www.codeave.com/javascript/code.asp?u_log=7014
    Last edited by PUBH; 05-13-2003 at 12:40 AM.

  12. #12
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    389
    Hi PUBH!

    You're a star! That did it

    The same thing obviously happened in my javascript quote added in my first post, only I didn't pick it up (d'oh).

    My close window javascript snippet of course has the two as one word.... as it works... but when I have copied and pasted from here I've added the space and not noticed. (told you I was feeling very blonde today!)

    Thanx again
    Pia
    Chalice Web at www.chaliceweb.com.au
    CPanel Shared and Reseller Hosting

  13. #13
    Join Date
    Jan 2003
    Location
    Glendale, Arizona, USA
    Posts
    165
    No problem!

    Glad I could pass along some of my knowledge. I've been so bored recently that I've been doing all sorts of weird things with my time like http://www.planetubh.com/links/ where I plan on adding all my commonly visited websites (gets extremely old having to type it again because it gets shoved off your history or whatever it is called... I'm still surprised I was able to get the counting thing to work, lol).

    Just remember that most errors that completely stump you usually involve something extremely simple (such as forgetting to add a quote, backslash, semi-colon, space, etc).

  14. #14
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    you have a space in the word javascript.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •