将 javascript 变量中保存的值传递给同一 html 页面上的 iframe 调用的最佳方法是什么?我正在尝试通过将广告投放 javascript 代码(典型的document.write('<script type="text/javascript" src=".."
)移动到单独的 iframe 中来改善我网站的页面响应时间。(基于此贴)
对广告服务器的请求通常需要一个种子变量,每个站点声明一次,并在客户端每次加载页面时递增。我想要做的是将种子变量传递到我的 iframe 部分调用的文档中。
种子变量在我的主 html 文档的“head”标签中初始化:
<head>
<script type="text/javascript">
<!--
custom_seed=1;
//-->
</script>
</head>
稍后在 html 文档中,我通过 iframe 发出请求,该 iframe 返回调用广告服务器所需的 html。
<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>
'somepage.html' 中返回的 html 有一个用于调用广告服务器的脚本,需要使用之前声明的种子变量作为参数:
<script type="text/javascript">
document.write('<script type="text/javascript" src="http://ad.server.net/...seed='+ custom_seed +'?"></script>');
custom_seed++;
</script>
实现这一目标的好方法是什么?