passing in javascript values into iframe tag

Posted by Cedar Jensen on Stack Overflow See other posts from Stack Overflow or by Cedar Jensen
Published on 2010-04-12T21:32:39Z Indexed on 2010/04/12 21:53 UTC
Read the original article Hit count: 309

Filed under:
|
|

What's the best way to pass in the value held in a javascript variable into an iframe call on the same html page? I'm trying to improve my site's page response times by moving ad serving javascript code (the typical document.write('<script type="text/javascript" src="..") into a separate iframe. (Based on this posting)

The request to the ad server typically require a seed variable declared once per site and incremented each time page is loaded by the client. What I want to do is pass in the seed variable into the document invoked by my iframe section.

The seed variable is initialized in the 'head' tag of my main html document:

<head>
    <script type="text/javascript">
    <!--
    custom_seed=1;  
    //-->
    </script>
</head>

Later in the html document, I make the request through an iframe which returns the html necessary to invoke the ad server.

<body>
<!-- a bunch of html to display the page -->
<iframe src="somepage.html" width="100%" height="100%">
<p>No support for iframe</p>
</iframe>
</body>

The html returned in the 'somepage.html' has a script used to call the ad server and needs to use the earlier declared seed variable as a parameter:

<script type="text/javascript">
    document.write('<script type="text/javascript" src="http://ad.server.net/...seed='+ custom_seed  +'?"></script>');
    custom_seed++;
    </script>

What's a good way to achieve this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html