www.webdeveloper.com
Results 1 to 9 of 9

Thread: Passing an increment variable into a window.open page?

  1. #1
    Join Date
    Mar 2010
    Posts
    701

    Passing an increment variable into a window.open page?

    I have a variable with a number value. I use variable++ to increase the value of the variable. How can I pass the new varible into a new window opened with window.open?

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    Assuming the new web page is on your domain, you can use either cookies or append a query string to the new web pages's url in window.open and then parse the query string in the new web page to get the variable's value if the new web page is a html file. If it's a PHP script, the variable will be stored $_GET[].

  3. #3
    Join Date
    Mar 2010
    Posts
    701
    How do I use cookies to store variables?

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    When you have a chance, maybe have a look at this site which will show how to do all sorts of things relating to website development.

    http://www.w3schools.com/

  5. #5
    Join Date
    Mar 2010
    Posts
    701
    Thanks, I've using that site since I started learning HTML and javascript. But the cookies section is confusing to me.

  6. #6
    Join Date
    Mar 2010
    Posts
    701
    Aren't there any other ways? I tried cookies but they are too confusing.

  7. #7
    Join Date
    Mar 2010
    Posts
    2,803
    Quote Originally Posted by narutodude000 View Post
    Aren't there any other ways? I tried cookies but they are too confusing.
    Yes, there are and I mentioned it in the second part of my initial reply to you.

  8. #8
    Join Date
    Mar 2010
    Posts
    701
    PHP's even more confusing :P
    I found another option here: http://www.webdeveloper.com/forum/sh...d.php?t=226990
    Can you help me out? Sorry for all the trouble.

  9. #9
    Join Date
    Mar 2010
    Posts
    2,803
    Quote Originally Posted by narutodude000 View Post
    PHP's even more confusing :P
    I found another option here: http://www.webdeveloper.com/forum/sh...d.php?t=226990
    Can you help me out? Sorry for all the trouble.
    I only mentioned php because you didn't say whether the new window was displaying a plain html file or html generated from a php file.

    You can send a query string to a pure html file and then parse the query string in javascript to get the values of the parameters.

    You can use the following html file as a template target html file that will parse any query string sent to it and display the values on your screen.

    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Form Processor</title>
    </head>
    <body>
    <script type="text/javascript">
    <!-- HIDE FROM INCOMPATIBLE BROWSERS
    if (window != top)
     top.location.href=location.href
    document.write("<h1>Your form has been submitted!</h1><h2>You entered the following data:</h2>");
    var formData = location.search;
    formData = formData.substring(1, formData.length);
    while (formData.indexOf("+") != -1) {
     formData = formData.replace("+", " ");
    }
    formData = unescape(formData);
    var formArray = formData.split("&");
    for (var i=0; i < formArray.length; ++i) {
     document.writeln(formArray[i] + "<br />");
    }
    // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles