T
Thomas 'PointedEars' Lahn
[...] I need to integrate my code with an external script.
The external script is using document.write(<iframe...)
and my script should decide if to write the external script..
document.write("<script...>") (which writes an Iframe element)
This is almost always nonsense. Why do you not include the generated
`script' element in the first place?
OR
write my Iframe
document.write("<iframe...")
so I need to stick with this logic. [...]
No, you don't. As Ann (Giggle Girl) pointed out already, you can modify the
`iframe' element generated by the "external script" afterwards. Which
should be reliable on cached reload in contrast to your efforts of cheating
the cache somehow.
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function modifySrc()
{
if (typeof window != "undefined"
&& window.frames
&& window.frames[0]
&& Math.random() > 0.5)
{
window.frames[0].src = "http://www.yahoo.com/";
}
}
</script>
</head>
<body onload="modifySrc()">
...
<!-- "external script" that generates an
iframe[src="[URL]http://www.google.com/[/URL]"] element;
let it be the only one here for simplicity of
the example -->
<script src="..." type="text/javascript"></script>
...
</body>
PointedEars