SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member gmn17's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Iframe script, can't make work in Safari.

    I found this script which is great cause you can have a list of iframe links and they will not load at all when the main page loads :

    <script language="Javascript">
    mes_pr = "[Snap Open]"
    mes_cpr = "[Snap Close]"

    function preview(link)
    {
    var iframe = self.document.all['IF'+link.id];
    if(link.innerText == mes_pr)
    {
    if(iframe)
    {
    iframe.src = link.href;
    iframe.style.height = 500;
    iframe.style.visibility = 'visible';
    }
    else
    link.insertAdjacentHTML('AfterEnd', '<br><IFRAME id=IF'+link.id+' width=95% height=500 SRC=\"'+link.href+'\"></IFRAME>');
    link.innerText = mes_cpr;
    }
    else
    {
    if(iframe)
    {
    iframe.style.visibility = 'hidden';
    iframe.style.height = 0;
    iframe.style.width = 0;
    link.innerText = mes_pr;
    //iframe.src = 'about:blank';
    }
    }
    }
    </script>
    <body>
    <a href="http://www.google.com" id="L1" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    <br>
    <br>
    <a href="togglediv.htm" id="L2" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    <br>
    <br>
    <a href="http://www.yahoo.com" id="L3" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    </body>

    It only worked in IE and it would only work once so I fixed it by taking out the last width statement and it opened and closed as often as you wanted, so I decided to use WebFx Moz compatibility script(stripped a lot out of it) to get it to work in firefox it works fine in firefox;
    below is the code and other changes I made to the script, I would appreciate any help in getting this to work in apple, the WebFX guy Erik said it would not work in Apple but I got it to work one time but forgot which punctuation I added or deleted and messed it up :

    <html>
    <head>
    <title>SnapOpenTest</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style>
    iframe {
    border:0;
    frameborder:none;
    }
    </style>
    <script type="text/javascript">
    <!--
    var ie = /MSIE/.test(navigator.userAgent);
    var moz = !ie && navigator.product == "Gecko";
    function emulateHTMLModel() {
    function convertTextToHTML(s) {
    s = s.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>");
    while (/\s\s/.test(s))
    s = s.replace(/\s\s/, "&nbsp; ");
    return s.replace(/\s/g, " ");
    }
    HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
    var df; // : DocumentFragment
    var r = this.ownerDocument.createRange();
    switch (String(sWhere).toLowerCase()) {
    case "beforebegin":
    r.setStartBefore(this);
    df = r.createContextualFragment(sHTML);
    this.parentNode.insertBefore(df, this);
    break;

    case "afterbegin":
    r.selectNodeContents(this);
    r.collapse(true);
    df = r.createContextualFragment(sHTML);
    this.insertBefore(df, this.firstChild);
    break;

    case "beforeend":
    r.selectNodeContents(this);
    r.collapse(false);
    df = r.createContextualFragment(sHTML);
    this.appendChild(df);
    break;

    case "afterend":
    r.setStartAfter(this);
    df = r.createContextualFragment(sHTML);
    this.parentNode.insertBefore(df, this.nextSibling);
    break;
    }
    };
    HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var df = r.createContextualFragment(sHTML);
    this.parentNode.replaceChild(df, this);
    return sHTML;
    });
    HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
    this.innerHTML = convertTextToHTML(sText);
    return sText;
    });
    var tmpGet;
    HTMLElement.prototype.__defineGetter__("innerText", tmpGet = function () {
    var r = this.ownerDocument.createRange();
    r.selectNodeContents(this);
    return r.toString();
    });
    HTMLElement.prototype.__defineSetter__("outerText", function (sText) {
    this.outerHTML = convertTextToHTML(sText);
    return sText;
    });
    HTMLElement.prototype.__defineGetter__("outerText", tmpGet);
    HTMLElement.prototype.insertAdjacentText = function (sWhere, sText) {
    this.insertAdjacentHTML(sWhere, convertTextToHTML(sText));
    };
    }
    if (moz)
    emulateHTMLModel();
    where = "link.id"
    crackle = "[Snap Open]"
    pop = "[Snap Close]"
    function preview(link) {
    var iframe = document.getElementById(['IF'+link.id]);
    if(link.innerText == crackle)
    {
    if(iframe)
    {
    iframe.src = link.href;
    iframe.style.height = 400;
    }
    else
    document.getElementById(link.id).insertAdjacentHTML('AfterEnd','<iframe id=IF'+link.id+' width=95% frameborder=no height=400px src='+link.href+'></iframe>');
    link.innerText = pop;
    }
    else
    {
    if(link.innerText == pop)
    {
    if(iframe)
    {
    iframe.style.height = 1;
    link.innerText = crackle;
    }
    }
    }
    }
    //-->
    </script>
    </head>
    <body style="margin:0">
    <a href="http://www.google.com" id="L1" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    <br>
    <br>
    <a href="togglediv.htm" id="L2" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    <br>
    <br>
    <a href="http://www.yahoo.com" id="L3" OnClick="preview(this);return false" Title="Click to see where answer was found">[Snap Open]</a>
    </body>
    </html>

  2. #2
    SitePoint Member gmn17's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that if this script if it can work somehow in safari, will maybe if this line was reversed somehow
    var moz = !ie && navigator.product == "Gecko";
    var Gecko = !ie && navigator.product == "moz";
    and another line added for safari support


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •