How to pass url parameters to iframe?

Suppose I have the following webpage

www.fake.com/sample.html 

I could pass some parameters to this web page, for example

 www.fake.com/sample.html?count=10&format=gold 

There is an iframe on this page, I would like to pass any parameters that the main page falls into a closed iframe. If the main page is called like that

 www.fake.com/sample.html?count=10&format=gold 

the iframe on the sample page should be called with the same parameters.

 <iframe src="www.fake.com/framed_page.html?count=10&format=gold"></iframe> 

What is the easiest way to do this?

+6
javascript html
source share
2 answers

In the javascript of the child document ( framed_page.html ) you can call window.parent.location to get the location object sample.html . Call window.parent.location.search to get the query string

+4
source share

The easiest and most reliable way (because it does not require JavaScript) is to use the server language to compile the correct iframe URL from the QUERY_STRING server variable.

In PHP:

 <iframe src= "www.fake.com\framed_page.html?<?php echo $_SERVER["QUERY_STRING"]; ?>"> </iframe> 
+3
source share

All Articles