Results 1 to 5 of 5

Thread: parameter from main browser to popup

  1. #1
    Join Date
    Apr 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question parameter from main browser to popup

    I create 2 pages:
    *** page 1 as following:
    <head>
    <script language='javascript'type='text/javascript'>
    function openPopup()
    {
    var popup = open('page2.htm', 'page2');
    txt = document.getElementById('txtParam');
    popup.document.all.txtReceive.innerHTML = txt.value;
    }
    </script>
    </head>
    <body>
    Paramater : &nbsp <input id="txtParam" type="text">
    <input id='button1' type='button' value='Open' onclick="openPopup();">
    </body>

    *** page 2 as following:
    <body>
    <table border="1" width="100%" id="table1">
    <tr>
    <td width="179">Receive Parameter:</td>
    <td id='txtReceive'> </td>
    </tr>
    </table>
    </body>

    With the code above, I want to pass parameter from a browser to a popup. But it just works on local, doesn't work on web server. I don't know the reason why. So I don't know how to fix.
    Please help solve this problem

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,023
    Thanks
    44
    Thanked 3,208 Times in 3,170 Posts
    Blog Entries
    12

    Default

    On page one have:

    HTML Code:
    <input type="text"><input type="button" value="click" onclick="window.open(page2.htm?var1='+this.previousSibling.value)">
    On page2.htm have:

    HTML Code:
    <span id="rec"></span>
    <script type="text/javascript">
    if (location.search.indexOf('?var1=')>-1)
    document.getElementById('rec').innerHTML=unescape(location.search).replace(/^.?var1=/, '')
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank a lot for your help.
    But in the case I want to pass many parameters to the second page, would you please to tell me the solution.
    By the way, would you please to explain for me the reason 2pages I've coded just work properly on local drive?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,023
    Thanks
    44
    Thanked 3,208 Times in 3,170 Posts
    Blog Entries
    12

    Default

    Hard to say, it might be your server. In any case, your code is probably IE specific, with its use of 'document.all' and employs the window.open() method in a shorthand sort of way that could be trouble. Another thing is that when passing info between windows, browsers can get pretty picky about just what refers to what. Just playing around, this scheme worked in IE, Opera and FF on one of my servers as well as locally and could be expanded to accommodate any number of variables. ONLY problem is, it REQUIRES javascript (PHP is generally better for this sort of thing):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <!-- saved from url=(0014)about:internet -->
    <!-- this and above comment should be removed for live, non-demo use -->
    <head>
    <title>page1</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function openPopup(){
    var txt = document.getElementById('txtParam');
    window.passed1 = txt.value;
    var popup = window.open('page2.htm', 'page2', 'width=400, height=300');
    }
    </script>
    </head>
    <body>
    Paramater : &nbsp <input id="txtParam" type="text">
    <input id='button1' type='button' value='Open' onclick="openPopup();">
    </body>
    </html>
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <!-- saved from url=(0014)about:internet -->
    <!-- this and above comment should be removed for live, non-demo use -->
    <head>
    <title>page2</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    onload=function(){
    document.getElementById('txtReceive').innerHTML=opener.passed1;
    }
    </script>
    </head>
    <body>
    <table border="1" width="100%" id="table1">
    <tr>
    <td width="179">Receive Parameter:</td>
    <td id='txtReceive'> </td>
    </tr>
    </table>
    </body>
    </html>
    Last edited by jscheuer1; 04-24-2006 at 02:49 PM. Reason: bring script tag attributes to current standard and simplify 'sending' code
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    My English is not good. So I cannot talk any sentence better than "Thank a lot". Anyway, thanksssss you a lot.

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
  •