4/23/2024 0 Comments Html code as iframe js srcdocIn that case you could use $(this).hide() if jQuery is available or =”hidden” with plain, vanilla JavaScript. You could also design an image behind your iframe and hide the iframe when offline. This simple message is just a proof-of-concept. $(elem).attr('onerror',"'srcdoc','You need to be online to view this content.') ").attr('onload', "if(navigator.onLine=false) eval(this.getAttribute('onerror')) ") }) }) Ĭaution: Using this global technique, you may also want to check to make sure you’re only altering iframes where the src attribute is online content ( e.g., contains ://). Here’s how you would do the same exactly thing, but with a single code block ( i.e., not hand-altering every iframe in your document). This could also be done with in5 content, by attaching the JavaScript as an external resource. Handling all iframes with a single block of code I purposely wrote the code so that everything could be included with the iframe itself, because many of our in5 customers are pasting the iframe embed code into their InDesign documents for digital publication.Īlternatively, you could write a block of code that handles an entire document full of iframes. This jsfiddle has the source code for 4 different examples. I used the strict equivalence operater (=), as opposed to the equivalence operator (=), to ensure that this would not be triggered if navigator.onLine was undefined, which would be the case in an older browser. Since I’m lazy and I don’t like to re-write (and re-writing introduces opportunities for mistakes), if the browser is offline, this will execute the code that was already written for the onerror attribute. Onload="if(navigator.onLine=false) eval(this.getAttribute('onerror')) " So I added the following onload attribute to the iframe tag. If a browser supports the srcdoc attribute, it will override the content specified in the src attribute (if present). Tip: This attribute is expected to be used together with the sandbox and seamless attributes. Newer browsers (including Chrome and Safari) support the navigator.onLine property. The srcdoc attribute specifies the HTML content of the page to show in the inline frame.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |