2

I have an iframe without src. This because the iframe only shows webpage content (from the src) when a user clicks a button (the src is then replaced by a webpage URL). That button is already working. But when nobody clicks the button, the iframe has to show some simple default text instead of that webpage. In my example I have written the text line 'This text must be displayed by default.'. Why is the text not showing up? I need to keep the onload javascript, because that is important for the functionality of the iframe.

<iframe src="" class="prodframe pc" style='bottom:0px;position:absolute;width:90%;height:73%;margin:0px auto;left:0;right:0;border:none;background:none transparent;' frameborder='0' scrolling='auto' allowtransparency='true' onload='window.onmessage=function(e){var c=0;var o=document.getElementById("zoekframe");if(o.offsetParent){do{c += o.offsetTop;}while(o = o.offsetParent);};scrollTo(0,c);};' id=zoekframe>This text must be displayed by default.</iframe>

I have a fiddle on the following link: https://jsfiddle.net/mfhdwmya/

Cinzel
  • 215
  • 3
  • 13
  • for clarity: the button that replaces the content is just background information, you don't have to do anything with that. Only concern is how to show that simple text line. – Cinzel Dec 28 '15 at 19:07

1 Answers1

1

This question is awfully similar to Alternate text for iframes

The accepted solution for that one is:

<script>
$(function () {

    $("iframe").not(":has([src])").each(function () {

    var ifrm = this;

    ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;

    ifrm.document.open();
    ifrm.document.write($(this).attr("alt"));
    ifrm.document.close();

    });

});
</script>

I'd comment, but my reputation was not yet enough.

Community
  • 1
  • 1
Appelemac
  • 192
  • 6