Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass url parameters onto a iframe?

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

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

the iframe in the sample page should be called with those same paramters.

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

What is the easiest way to do this?

like image 496
Janak Avatar asked May 13 '10 10:05

Janak


2 Answers

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

like image 50
Adam Hopkinson Avatar answered Oct 12 '22 17:10

Adam Hopkinson


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.

In PHP:

<iframe src=
    "www.fake.com\framed_page.html?<?php echo $_SERVER["QUERY_STRING"]; ?>">
</iframe>
like image 21
Pekka Avatar answered Oct 12 '22 15:10

Pekka