Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Problema con js iframe

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    117

    Problema con js iframe

    Salve ragazzi,

    ho inserito nel mio sito questo js (ridimensiona le pagine in relazione allo spazio occupato da un iframe)
    <script language="javascript" type="text/javascript">
    function reSize() {
    try {
    var oBody = ifrm.document.body;
    var oFrame = document.all("ifrm");

    oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
    oFrame.style.width = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
    }
    //An error is raised if the IFrame domain != its container's domain
    catch (e) {
    window.status = 'Error: ' + e.number + '; ' + e.description;
    }
    }
    </script>

    poi nel body questo:
    <body onload="reSize()">

    ed infine la tag del iframe:
    <div id="content">
    <iframe name="Content" id="ifrm" width="100%" style="background-color:White" src="link"
    frameborder="0" marginwidth="0" marginheight="0" scrolling="no" onload="reSize();"></iframe>
    </div>

    Non capisco come mai ogni volta che cambio pagina news in iframe (vengono visualizzate le news del sito) la pagina non viene ridimensionata in relazione allo spazio occupato dal iframe, mantenedo la dimensione del iframe della prima pagina visualizzata.

    Sapete perchè ?

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Perché la funzione reSize() si scatena sia nella pagina contenitore e nel iframe solo primo caricamento dopo muovendoti solo nel iframe la funzione si scatena solo in quest'ultimo.
    Soluzioni o ricarichi tutta la pagina o richiami ma funzione dalla dalla pagina iframe
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    117
    Risolto con questo js:

    <script language="javascript" type="text/javascript">
    //Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
    //Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
    var iframeids = ["myframe", "myframe2", "myframe3", "myframe4", "myframe5"]

    //Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
    var iframehide = "yes"

    var getFFVersion = navigator.userAgent.substring(navigator.userAgent. indexOf("Firefox")).split("/")[1]
    var FFextraHeight = 0;

    function resizeCaller() {
    var dyniframe = new Array()
    for (i = 0; i < iframeids.length; i++) {
    if (document.getElementById)
    resizeIframe(iframeids[i])
    //reveal iframe for lower end browsers? (see var above):
    if ((document.all || document.getElementById) && iframehide == "no") {
    var tempobj = document.all ? document.all[iframeids[i]] : document.getElementById(iframeids[i])
    tempobj.style.display = "block"
    }
    }
    }

    function resizeIframe(frameid) {
    var currentfr = document.getElementById(frameid)
    if (currentfr && !window.opera) {
    currentfr.style.display = "block"
    if (currentfr.contentDocument && currentfr.contentDocument.documentElement.scrollHe ight) { //ns6 syntax
    currentfr.height = 1;
    currentfr.parentNode.style.height = "auto";
    currentfr.height = currentfr.contentDocument.documentElement.scrollHe ight + FFextraHeight;
    }
    else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
    currentfr.height = currentfr.Document.body.scrollHeight;
    if (currentfr.addEventListener)
    currentfr.addEventListener("load", readjustIframe, false)
    else if (currentfr.attachEvent) {
    currentfr.detachEvent("onload", readjustIframe) // Bug fix line
    currentfr.attachEvent("onload", readjustIframe)
    }
    }
    }

    function readjustIframe(loadevt) {
    var crossevt = (window.event) ? event : loadevt
    var iframeroot = (crossevt.currentTarget) ? crossevt.currentTarget : crossevt.srcElement
    if (iframeroot)
    resizeIframe(iframeroot.id);
    }

    function loadintoIframe(iframeid, url) {
    if (document.getElementById)
    document.getElementById(iframeid).src = url
    }

    if (window.addEventListener)
    window.addEventListener("load", resizeCaller, false)
    else if (window.attachEvent)
    window.attachEvent("onload", resizeCaller)
    else
    window.onload = resizeCaller
    </script>

    E' possibile impostare anche più iframe.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.