0

How do I pass a query string to a HTML frame?

I have the following HTML in index.html:

<HTML>
<FRAMESET rows="200, 200" border=0>
  <FRAMESET>
    <FRAME name=top scrolling=no src="top.html">
    <FRAME name=main scrolling=yes src="/cgi-bin/main.py">
  </FRAMESET>
</FRAMESET>
</HTML>

The frame src is main.py which is a python cgi script. This is in main.py:

import cgi
form = cgi.FieldStorage()
test = form.getvalue('test')

Suppose I call the url using index.html?test=abcde. How do I pass the query string to main.py? Is this possible using javascript?

MD6380
  • 1,007
  • 4
  • 13
  • 26
  • You should definitly *not* use cgi. It's outdated and python is way more powerful than cgi is. You maybe wanna take a look at a microframework like [Flask](http://flask.pocoo.org) or [Bottle](http://bottlepy.org/docs/dev/) or a all-in-one framework like [Django](https://www.djangoproject.com/). – dav1d Aug 19 '12 at 17:31
  • @dav1d Thanks for the recommendation, but I'm adding functionality to an old simple existing web tool that we have so I'm limitied to whats already there. – MD6380 Aug 19 '12 at 17:39

2 Answers2

1

This should help you get variables from the query string, which you can use to build your custom queryString. Or if you want to pass the query string as it is to the frame, then you could get it a simpler fashion.

var queryString = window.location.href.split('index.html?')[1];

Now, as for passing it to the frame, it should be easy because you'd just be appending the query string to the frame element's src attribute.

Community
  • 1
  • 1
Prasanth
  • 5,230
  • 2
  • 29
  • 61
  • Thanks, this led me to the right solution. I used an onload event to call a javascript method that builds a custom query string for the frame src attribute. – MD6380 Aug 19 '12 at 18:35
0

Not sure if this will work (untested), but perhaps you can load the query parameters onload using jQuery? Here is a proof of concept:

<html>
    <head>
    //Load jquery here, then do the following:
    <script type="text/javascript">
        $(document).ready(functin(){
        // navigator.href holds the current window's q params
        // you will have to write this funciton (fairly easy).
        var q = get_query_paramenters(navigator.href); 
        var top = $("<frame name=top scrolling=no src='top.html'></frame>"),
        main = $("<frame name=main scrolling=yes></frame>");
        main.attr("src", "/cgi-bin/main.py?" + q);

        $("#myframeset").append(top).append(main);

    });
    </script>
    </head>
<body>
    <FRAMESET rows="200, 200" border=0>
        <FRAMESET id='myframeset'>

        </FRAMESET>
    </FRAMESET>
</body>
</html>

Hope that helps.

Eudis Duran
  • 742
  • 3
  • 16