IE hack for javascript & iframe
I have a site with URL links on a Links page. Each link takes you to a Frame page that is a big iFrame that pulls in the given URL. I'm using javascript to do this and it works in FF, Safari, Opera and Chrome, but not IE. Does anyone know what I can do to get it to work in IE?
I've built it in WordPress. I have this in Head section between tags and tags:
<script type="text/javascript" language="javascript">
function loadIF() {
iFrameSrc=location.href.split('?');
if ( iFrameSrc[1] !=开发者_如何学编程 null ) {
document.getElementById('external').src=iFrameSrc[1];
}
else {
document.getElementById('external').src='default_page.htm'
}
}
</script>
Then I put this in header.php as well:
<body onload="loadIF()" <?php body_class(); ?>>
Here is the link markup:
<a href="/frame1?http://www.website.com">Website</a>
Thanks- Chris
You seem to be splitting the location on the ?
does that mean you are trying to get the parameters?
if so:
iFrameSrc = location.search;
if(iFrameSrc)
{
... // Code here
}
else
{
... // Code here
}
or try
if(iFrame && iFrame.length > 2)
{
... // Code here
}
else
{
... // Code here
}
EDIT ok so after seeing your edit i thought i better add this:
Take the first code example I gave you and replace the first ... // Code here
with:
document.getElementById('external').src= iFrameSrc.substr(1); // This will remove the leading question mark.
UPDATE
<html>
<head>
<title></title>
<script type="text/javascript">
function iFrameIF()
{
iFrameSrc = location.search;
if (iFrameSrc)
{
alert(iFrameSrc.substr(1));//document.getElementById('external').src = iFrameSrc.substr(1);
}
else
{
alert(); //document.getElementById('external').src = 'http://about:blank'
}
}
</script>
</head>
<body onload="iFrameIF()">
<iframe width="100%" height="1000" marginheight="1" marginwidth="1" align="top" allowtransparency="true" frameborder="0" name="external" id="external"></iframe>
<br />
</body>
</html>
typing into ie: file://path/to/file.html?test
got me an alert saying "test"
精彩评论