Click to See Complete Forum and Search --> : Loading iframe src with variable contents
nicks
05-05-2004, 02:34 AM
I am trying to find a way to load an iframe's src attribute with a JavaScript variable that contains a complete HTML page as opposed to a reference to a URI containing a complete HTML page.
I was thinking there may be a way to create and populate an object that mimics a URI and providing that as the source to the iframe but I don't know how to achieve this.
Sorry if this has been asked before but I did a search and could not find the answer.
Any Ideas?
Thanks,
Nick S.
Pittimann
05-05-2004, 02:46 AM
Hi!
You could use a div instead of an iframe and then say something like: document.getElementById('idGoesHere').innerHTML=yourVariable
Cheers - Pit
nicks
05-05-2004, 03:06 AM
Hi Pit,
Thanks for your suggestion, it works just fine, but unfortunately, I require the data to be populated within an iframe, not a div.
I tried changing the div to iframe but got an error stating innerHtml is not a property of iframe.
I then tried replacing innerHtml with dataSrc and src, no errors this time, but no data being displayed in iframe either!
Any other ideas?
Thanks,
Nick S.
Pittimann
05-05-2004, 03:25 AM
Hi!
This example will cause an error in Mozilla, if the user refreshes the page after loading. Otherwise it works in IE and Mozilla:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var myvar='<span style="color: red;">xxxxxxxxxx</span>';
//-->
</script>
</head>
<body>
<iframe src="javascript:parent.frames.myvar"></iframe>
</body>
</html>
Please remove the space between "java" and "script" in the src...
Cheers - Pit
nicks
05-05-2004, 03:37 AM
Hi Pit,
That is exactly what I needed and it works exactly as I expected. And I don't even have to filter out the pop-up code anymore!
Loading the iframe using this method seems to ignore any javascript in that variable which is exactly what I wanted.
Thank you very much for your expert (not to mention quick!)help Pit, you guys are great, in fact this entire forum is terrific.
Thanks,
Nick S.
Pittimann
05-05-2004, 03:40 AM
Hi!
You're welcome! :D
Cheers - Pit