SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: java

  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Location
    Rockford, IL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    java

    I have a VERY odd thing happening and I don't know if it's the settings on my new laptop somewhere that I am missing or if the code is broken.

    This works on my desktop but not on my laptop - I cannot figure out why; any help would be appreciated.

    Code:
    <body onUnload="opener.location=('article.php?id=<?php echo $id; ?>')">
    </body>
    <script language="JavaScript">
    	window.close();
    </script>
    Basically I have a main page, that calls a popup form, that form submits to another (php) page (there's some mysql stuff above the code I posted) and then once then it closes the form page and updates the main page, like I said, it works great on my desktop, but not on my laptop.

    Any idea why it would not work on my desktop or another way of refreshing the main page (opener) would be greatly appreciated.

    Thank you,

    --Tone

  2. #2
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps the window.close() is being executed before the onload function, even though it is technically not in the document body. Try this:

    Code:
    <head>
    <script type="text/javascript">
    function myFunc() {
    window.opener.location.href = "article.php?id=<?=$id; ?>";
    window.close();
    }
    </script>
    <head>
    <body onload="myFunc()">
    </body>

  3. #3
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really don't get the point of this code. Are you opening a second window just to have it reload the opener and close itself? If so, you can reload the opener without using a popup. Just use window.location.reload().

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The document.close Javascript needs to be inside of the body of the page.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Nov 2005
    Location
    Rockford, IL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow - thanks guys for the quick replies - basically here is the full code - like I said, main page opens a form - this form posts to this add_article.php file which posts the mysql stuff and then closes the window and updates the main page.

    Code:
    <?php
    	session_start();
    ?>
    		<?php
    	
    	include "authenticate.inc.php";
    	include "conn.php";
    	//article table id
    	$id = $_REQUEST['id'];
    
    .... more mysql stuff removed	
    	
    ?>
    
    <html>
    <body onUnload="opener.location=('article.php?id=<?php echo $id; ?>')">
    </body>
    <script language="JavaScript">
    	window.close();
    </script>
    </html>

    MAIN PAGE -> popup FORM -> add_article.php (above) - close popup window, refresh main page.

    Like I said, it works on my desktop but not my laptop using the same (latest updated) ie6. Why it doesn't work on my laptop I do not know.

    --Tone
    Hardware Ranking - Hardware Reviews, News and Shopping.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall
    The document.close Javascript needs to be inside of the body of the page.
    Yes, but it would get executed before the body's onload event fired. The onload event doesn't fire until the body is completely loaded. An inline call to window.close() would be executed as soon as it's parsed.

  7. #7
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shackbase
    wow - thanks guys for the quick replies - basically here is the full code - like I said, main page opens a form - this form posts to this add_article.php file which posts the mysql stuff and then closes the window and updates the main page.
    Here's what works in my apps that do the same thing:

    Code:
    <form action="add_article.php" target="main" onsubmit="setTimeout('window.close()',1000)">
    where "main" is the name of the opener. If you use an onsubmit validator, you would need to add the setTimeout to the part of your validator that returns true (i.e., permits the form to be submitted).

  8. #8
    SitePoint Member
    Join Date
    Nov 2005
    Location
    Rockford, IL
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A.dotty.dot - what you came up with in your first reply #2 - seems to work A-100% on my laptop as well.

    THANK YOU SO MUCH - If you PM me your paypal I'll throw $5 or so your way as a thank you!

    Again - thank you so much all of you for the quick help,

    --Tone
    Hardware Ranking - Hardware Reviews, News and Shopping.


Bookmarks

Posting Permissions

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