6

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?

2
  • FYI, your slashes are the wrong way round Commented May 13, 2010 at 10:51
  • Fixed the slashes. Also, i don't have access to a server-side language Commented May 14, 2010 at 14:11

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

http://stackoverflow.com/questions/523266/how-can-i-get-a-specific-parameter-from-location-search My favorite is the @JustinJohnson answer.
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.

In PHP:

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

3 Comments

That's what I was going to go with, but there's no mention of php in the OP.
Then again, the question does ask for the query string in the iframe src attribute rather than in the iframe dom.
@adam yeah, it would need to be put into the load event to work with JS - perfectly fine but won't work with JS disabled obviously, which is the only downside. It will depend on what the OP can use.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.