#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    Hope someone can help a javascript novice.

    I am automatically submitting a form (hidden from the visitor) via form.submit. The form tag is coded with a target parameter, in this case 'phppage', and an action of "/check.php3".
    check.php3 sets a cookie, calls itself back to make sure cookies are enabled, then redirects to another URL. Since I want this new URL (once it's been redirected to) to be in a new open window, I am also defining a window.open (url,name,features) with url of '', name of the target page 'phppage' that was defined in the form tag, and features including no toolbar and a specific width and height - along with the form submit.

    I've tried putting the window.open both before and after the form.submit, but either way, it creates a new blank page (with the correct features) AND a smaller window (without the features) with the correct results (the final URL destination).

    I originally tried the onsubmit in the form tag, but found out that it doesn't work if combined with a form.submit. So then I tried the window.open along with the form submit, but can't get the results I need.

    Can anyone help? Is there another way to do this?

    Sharon
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    81
    Rep Power
    15
    How are you handling your redirect? Usually the redirect is within a META tag in the head of the document. I assume the reason you have two windows popping up is one for the window.open() function and the other for the redirect within the META tag.

    Instead of redirecting from the META tag, open a new window based on what you determine from your cookie. Then do a document.write() to write some trivial code, including the META tag with the redirect, to the new window. Might look something like this:

    <SCRIPT>
    var trivial="<HTML><HEAD><META redirect line ><//HEAD><BODY><//BODY><//HTML>"
    var features="scrollbar=no,....."
    var title="mytitle"

    win1=window.open('blank.htm',title,features);
    win1.document.write(trivial);

    </SCRIPT>

    The above should write essentially a blank document to your popup including the meta tag with the redirect. Then the redirect should fire and load the requested url into the popup. At least that's the plan. Let me know if this works. This is just off the top of my head. I've used similar code for other purposes but have never written to a popup so I'm unsure of the document.write syntax in this case.

    P.S. You cannot write <SCRIPT>...js...</SCRIPT> to another window this way. At least I've not been able to.

    Russ

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by smmorrow:
    Hope someone can help a javascript novice.

    I am automatically submitting a form (hidden from the visitor) via form.submit. The form tag is coded with a target parameter, in this case 'phppage', and an action of "/check.php3".
    check.php3 sets a cookie, calls itself back to make sure cookies are enabled, then redirects to another URL. Since I want this new URL (once it's been redirected to) to be in a new open window, I am also defining a window.open (url,name,features) with url of '', name of the target page 'phppage' that was defined in the form tag, and features including no toolbar and a specific width and height - along with the form submit.

    I've tried putting the window.open both before and after the form.submit, but either way, it creates a new blank page (with the correct features) AND a smaller window (without the features) with the correct results (the final URL destination).

    I originally tried the onsubmit in the form tag, but found out that it doesn't work if combined with a form.submit. So then I tried the window.open along with the form submit, but can't get the results I need.

    Can anyone help? Is there another way to do this?

    Sharon
    [/quote]

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    Thanks for your reply, Russ. My redirect is actually happening in check.php3 - a PHP script, that does a redirect via a single statement:

    header("Location: $nextpage");

    Where $nextpage is the URL.

    I guess I could try adding your javascript code to the php page and see what happens. Since I needed to do something quickly, I was able to initiate a new open window earlier in the process - so that the new window already existed at the time of the cookie creation and redirect, and they automatically executed in this new window. That worked. But, it would be nice to know if this will work for future projects where I may not have the luxury of opening up a new window earlier in the process. So I'll save this information and give it a try when I get the opportunity.
    Again, thanks for your help.

    Sharon

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    Sharon,

    I have found a way round this problem by adding 'pauses' to the javascript. This essentially gives the popup window time to load fully before the form is submitted to it. The code I was using when I was having the problem was similar to this -

    window.open('','CallMePopUp','status=no,etc');
    document.form.target='CallMePopUp';
    document.form.submit();

    This was getting exactly the same problem you described i.e. 2 windows were opening - a blank popup and a new browser window containing the submitted form. However, I found that by using the 'setTimeout' javascript function I could delay the submission of the form slightly so that when it was submitted the popup window was fully loaded and had been recognised as the target.

    So the code that works looks like this -

    window.open('','CallMePopUp','status=no,etc');
    var set_timeout1=setTimeout("document.form.target='CallMePopUp';",100);
    var set_timeout=setTimeout("document.form.submit();",200);

    This basically delays setting the form target for 100 millisecs and the submission of the form by 200 millisecs, and seems to work (at least in IE4/5, NN4/5 for Windows).

    Hope that helps,
    Matt.


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by smmorrow:
    Hope someone can help a javascript novice.

    I am automatically submitting a form (hidden from the visitor) via form.submit. The form tag is coded with a target parameter, in this case 'phppage', and an action of "/check.php3".
    check.php3 sets a cookie, calls itself back to make sure cookies are enabled, then redirects to another URL. Since I want this new URL (once it's been redirected to) to be in a new open window, I am also defining a window.open (url,name,features) with url of '', name of the target page 'phppage' that was defined in the form tag, and features including no toolbar and a specific width and height - along with the form submit.

    I've tried putting the window.open both before and after the form.submit, but either way, it creates a new blank page (with the correct features) AND a smaller window (without the features) with the correct results (the final URL destination).

    I originally tried the onsubmit in the form tag, but found out that it doesn't work if combined with a form.submit. So then I tried the window.open along with the form submit, but can't get the results I need.

    Can anyone help? Is there another way to do this?

    Sharon
    [/quote]

Similar Threads

  1. more help needed in MFC
    By carol2003 in forum C Programming
    Replies: 8
    Last Post: December 19th, 2003, 02:59 AM
  2. Opening other programs
    By VBdumbie110 in forum Visual Basic Programming
    Replies: 4
    Last Post: November 14th, 2003, 01:25 AM
  3. New window and session_start hanging main window
    By james555 in forum PHP Development
    Replies: 7
    Last Post: August 6th, 2003, 06:08 PM
  4. Can I detect if a window object is already open?
    By mgreifenkamp in forum HTML Programming
    Replies: 0
    Last Post: November 12th, 2001, 01:06 PM
  5. custom everything in new window, how?
    By edwinx in forum HTML Programming
    Replies: 6
    Last Post: June 29th, 2001, 02:06 AM

IMN logo majestic logo threadwatch logo seochat tools logo