#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    8
    Rep Power
    0

    Question popup window doesn't work??(Javascript and some PHP)


    Hi, I just want to open a page in a popup window without all bars...
    I'm using the script below....but it doensn't open a popup window....can somebody help me with this?
    I'm totally no Javascript expert!
    So please use examples...

    In this script I'm also using some php because there has to be some variables send with the link to the popup page. (sorry about my english, it's not my native language)

    =================CODE===================
    <html>
    <head>

    <script>
    function popup_mailfriend()
    {mailfriend = window.open('send_to_friend.php', 'width=500,height=500,toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,titlebar=1 ')
    mailfriend.focus();
    }
    </script>

    </head>
    <body>

    <?
    echo "<a href='", "send_to_friend.php?section=$section&topic=$topic&subtopic=$subtopic&subsubtopic=$subsubtopic";

    echo "' onCLick='popup_mailfriend()'>Email this page to a friend</a>";
    ?>

    </body>
    </html>
    ===============END CODE================

    Thanks in advance for your help.

    - Boszy -
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    I don't know PHP, but here's an example of how to open a window

    Code:
    <html>
    <head>
    	<title>Untitled</title>
    	<script language="javascript">
    		function newWin() {
    			window.open('http:\\src','name','toolbars=0,....')
    		}	
    	</script>
    </head>
    
    <body>
    	<a href="javascript:newWin()">Open the window</a><!--There should be no space between javascript (forum does it automatically)-->
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    First, you missed a parameter in your open function call. The second parameter should be the oipened windows name. In this case you can use an empty string or you could use the name of the return variable(mailfriend).

    Secondly, if you want to send the GET response to the opened window, you must add the search string to the URL in the open function call (see example).

    Thirdly, you need to add a return false; in your onClick statement of your link. Links take the return value of a function called in their onclick event. If there is no return, it proceeds to execute the link itself.

    Lastly, you do not need to set the focus of the new window as when you create it, it has system focus by default. Hope this helps!

    PHP Code:
    <html
    <
    head

    <
    script
    function 
    popup_mailfriend() 
    {
    mailfriend 
    window.open(
    'http://www.clanmisfire.com/index.php?section=sfs&topic=topic&subtopic=subtopic&subsubtopic=subsubtopic',
    "",
    'width=500,height=500,toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,titlebar=1'
    //mailfriend.focus(); 

    </script> 

    </head> 
    <body> 

    <a href="http://www.clanmisfire.com"
     onCLick='popup_mailfriend(); return false;'>Email this page to a friend</a> 

    </body> 
    </html> 
    Note: I used my site to see a working url.
    Last edited by Nemi; July 21st, 2001 at 12:08 PM.
  6. #4
  7. CORNHOLIO!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    51
    Rep Power
    14
    onCLick='popup_mailfriend(id = 1,2,3 ....); return false;'>Email this page to a friend</a>

    could you do something like this? (not ment as an answer to the first question)
  8. #5
  9. No Profile Picture
    Divine Wind
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Mongo
    Posts
    24
    Rep Power
    0

    Re: popup window doesn't work??(Javascript and some PHP)


    Originally posted by Boszy

    <script>
    function popup_mailfriend()
    {mailfriend = window.open('send_to_friend.php', 'width=500,height=500,toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,titlebar=1 ')
    mailfriend.focus();
    }
    </script>

    </head>
    <body>

    <?
    echo "<a href='", "send_to_friend.php?section=$section&topic=$topic&subtopic=$subtopic&subsubtopic=$subsubtopic";

    echo "' onCLick='popup_mailfriend()'>Email this page to a friend</a>";
    ?>
    The problem is that the query string is not being passed. The solution depends on how you want the rest of your page to work. As far as I can tell I'd just have:

    <A HREF="#" onCLick="popup_mailfriend()">Email to friend</A>

    and then use PHP to write the link location into the JavaScript function:

    function popup_mailfriend() {
    mailfriend = window.open('send_to_friend.php?section=<?php $section ?>&topic=<?php $topic ?>&subtopic=<?php $subtopic ?>&subsubtopic=<?php $subsubtopic ?>', ETC.

    If the query string is visible in the URL you could use send_to_friend.php?<?php $QUERY_STRING ?>

    If you are using the JavaScript by linking it in from an external file they you may need to send the query string like:

    <A HREF="#" onCLick="popup_mailfriend(section=<?php $section ?>&topic=<?php $topic ?>&subtopic=<?php $subtopic ?>&subsubtopic=<?php $subsubtopic ?>)">

    function popup_mailfriend(queryString) {
    mailfriend = window.open('send_to_friend.php?'+queryString, ETC.

    Anyway thats what your problem is and one of the solutions above should help (although it may need some fixing as I've not tested the code).

    Emps

IMN logo majestic logo threadwatch logo seochat tools logo