Link to home
Create AccountLog in
Avatar of mrduckers
mrduckers

asked on

read URL variable and put into iframe src url string

Hi,
It is possible to read URL variable and put into iframe src url string

EG:
The page url is:
www.mypage.com?date=1/1/2008

In this page, I want to have an iframe with the code:
<iframe src="http://myotherpage.com/events.asp?date=[THE DATE IN URL]" width="100" height="100">

I can easily do this in asp, but the page has to be HTML and JavaScript only.

Thanks
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

mrduckers,

Use location.search to get the part starting with the ? character.  For the date use ...

var dt = window.location.search.toString().split('=')[1];

Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of mrduckers
mrduckers

ASKER

Hi,

I can get the URL variables out easy, its putting it in the iframe src that is the problem?

How would I write it?
Make a function to set the iframe url using:

document.getelementById("yourIFrameName").location.href;

Use onLoad= in the BODY tag of the parent page to call the function.
ASKER CERTIFIED SOLUTION
Avatar of Jeremy Daley
Jeremy Daley
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Whooops. You are correct. I meant to use:

frames["yourIFrameName"].location.href

This should be more compatible since I don't believe Opera supports the object method of setting the frame url, though I don't test anything in Opera myself...
Thanks, I'm using this
<script>
var search = location.search;
search = search.replace(/\?/,'');
var searchAttributes = search.split('&');
for(var no=0;no<searchAttributes.length;no++){
    var items = searchAttributes[no].split('=');
    eval("var "+items[0]+" = '"+items[1]+"';");
}
newDate = date
function populateIframe(){
      document.getElementById("myFrame").src = "https://www.xxxx.com.au/iframe/whatson.asp?date=" + newDate
}

</script>
</head>
<body onload="populateIframe()">
<h1>MBF Homepage</h1>
<iframe id="myFrame" width="390" height="400" frameborder="1" ></iframe>
</body>
</html>

anyway to stop the page reloading when it starts up?

Thanks.
can't say i understand what you mean by a page reloading on start up... can you be more descriptive?
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol