Log in

View Full Version : multiple iframe scripts not working



mdeanh
02-22-2013, 09:31 PM
I hope someone on here can help me out.
I have a script that I been using to load my iframe and resize to the window size. I been trying to add in a script that will allow me to make the Iframe target a content page but cannot get them both to run together correctly. Seams every script I try it overrides my resize script.

The <head> script for resizing is:
<script src="css/dw_viewport.js" type="text/javascript"></script>
<script type="text/javascript">
function setIframeHeight(id, h) {
var main = document.getElementById(id);
if (main) {
var winHt = dw_Viewport.getWinHeight();
main.style.height = Math.round( h * winHt ) + "px";
main.style.marginTop = Math.round( ( winHt - parseInt(ifrm.style.height) )/2 ) + "px";
}
}

window.onload = function() { setIframeHeight('main', .7); }
window.onresize = function() { setIframeHeight('main', .7); }

The <head> script for loading a new target page to iframe is:
<script type="text/javascript">

function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))

window.frames["main"].location=url
}
}

onload=loadIframe
</script>

I use the external link to load my page with targeted iframe is:
<a href="index.html?content.html">my content</a>

My Iframe:
<iframe name="main" id="main" src="index.html" allowtransparency="true" frameborder="0">Your browser doesn't allow viewing frames!</iframe>

If someone has a better script or can show me how to apply these 2 script to run together id appreciate it.
I have searched about adding multiple scripts but after trial and error I still didn't get any further.
Thanks

Beverleyh
02-23-2013, 07:11 AM
I think the easiest thing would be for you to post a link to the page in question. Although you've posted code fragments, it doesn't given us a picture of everything in context so its difficult to understand how everything is working together (or conflicting)

Please also provide links to any scripts you've used, at the developers site/demo - there may be things there that have been overlooked.

mdeanh
02-23-2013, 08:19 AM
I have saved 2 versions:
http://www.panelsusa.com/index2.html (is what i started with has a resizing script for the iframe I found it at http://www.dyn-web.com/tutorials/iframes/fluid/)

http://www.panelsusa.com/index3.html (is with the added targeting iframe script i found here at http://www.dynamicdrive.com/forums/showthread.php?20270-targeting-an-iframe-or-ajax-loaded-content-from-an-external-link) This script is preventing my original script for setting the iframe size.

Thanks

molendijk
02-23-2013, 11:23 AM
Replace onload=loadIframe with the following, then see what happens:

if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", loadIframe, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", loadIframe );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
loadIframe();
};
}
else
window.onload = loadIframe;
}

molendijk
02-23-2013, 04:08 PM
I tested what I suggested in my previous post with the links you gave us. It works.

mdeanh
02-23-2013, 10:30 PM
Thank you molendijk for the code revision!
It works perfectly, I since added a random text script to the page and had to add in a window.onload script to load the multiple scripts.
Everything displays perfectly now!