Lets say I have the following webpage
可以说我有以下网页
www.fake.com/sample.html
I could pass some parameters to that webpage, like so
我可以将一些参数传递给该网页,就像这样
www.fake.com/sample.html?count=10&format=gold
this page has an iframe in it, I would like to pass any parameters that the main page gets to the enclosed iframe. If the main page is called like so
这个页面里面有一个iframe,我想将主页面的任何参数传递给随附的iframe。如果像这样调用主页面
www.fake.com/sample.html?count=10&format=gold
the iframe in the sample page should be called with those same paramters.
应使用相同的参数调用示例页面中的iframe。
<iframe src="www.fake.com/framed_page.html?count=10&format=gold"></iframe>
What is the easiest way to do this?
最简单的方法是什么?
2 个解决方案
#1
4
In the javascript of the child document (framed_page.html
) you can call window.parent.location
to get the location object of sample.html
. Call window.parent.location.search
to get the query string
在子文档的javascript(framed_page.html)中,您可以调用window.parent.location来获取sample.html的位置对象。调用window.parent.location.search来获取查询字符串
#2
3
The easiest and most reliable way (because it doesn't require JavaScript to work) would be to use a server-side language to compose the correct iframe URL from the QUERY_STRING
server variable.
最简单,最可靠的方法(因为它不需要JavaScript工作)将使用服务器端语言从QUERY_STRING服务器变量组成正确的iframe URL。
In PHP:
<iframe src=
"www.fake.com\framed_page.html?<?php echo $_SERVER["QUERY_STRING"]; ?>">
</iframe>
#1
4
In the javascript of the child document (framed_page.html
) you can call window.parent.location
to get the location object of sample.html
. Call window.parent.location.search
to get the query string
在子文档的javascript(framed_page.html)中,您可以调用window.parent.location来获取sample.html的位置对象。调用window.parent.location.search来获取查询字符串
#2
3
The easiest and most reliable way (because it doesn't require JavaScript to work) would be to use a server-side language to compose the correct iframe URL from the QUERY_STRING
server variable.
最简单,最可靠的方法(因为它不需要JavaScript工作)将使用服务器端语言从QUERY_STRING服务器变量组成正确的iframe URL。
In PHP:
<iframe src=
"www.fake.com\framed_page.html?<?php echo $_SERVER["QUERY_STRING"]; ?>">
</iframe>