0

如何将查询字符串传递给 HTML 框架?

我在 index.html 中有以下 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>

框架 src 是 main.py,它是一个 python cgi 脚本。这是在 main.py 中:

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

假设我使用 index.html?test=abcde 调用 url。如何将查询字符串传递给 main.py?这可能使用javascript吗?

4

2 回答 2

1

应该可以帮助您从查询字符串中获取变量,您可以使用这些变量来构建您的自定义查询字符串。或者,如果您想将查询字符串按原样传递给框架,那么您可以获得一种更简单的方式。

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

现在,至于将其传递给框架,应该很容易,因为您只需将查询字符串附加到框架元素的src属性。

于 2012-08-19T18:03:02.593 回答
0

不确定这是否可行(未经测试),但也许您可以使用 jQuery 加载查询参数 onload?这是一个概念证明:

<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>

希望有帮助。

于 2012-08-19T18:03:06.113 回答