I have a webpage hosted online and I would like it to be possible that I could insert an IFRAME onto another webpage using some JavaScript.
How would this be the best way possible, that I just add my webpage URL to the JavaScript and that it work on all browsers?
Thanks
As long as the protocol, domain and port of the parent page and iframe match, everything will work fine. I added an example on how to use the window.
To generate iframe, you need to set a URL to embed, width and height, scroll, disable or enable border, specify border type, size and border color, and add the iframe Name. Then, click the “Create iframe“ button to generate HTML code and push the “Copy To Clipboard“ button for copying the result.
An inline frame (iframe) is a HTML element that loads another HTML page within the document. It essentially puts another webpage within the parent page. They are commonly used for advertisements, embedded videos, web analytics and interactive content.
IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.
You can use:
<script type="text/javascript"> function prepareFrame() { var ifrm = document.createElement("iframe"); ifrm.setAttribute("src", "http://google.com/"); ifrm.style.width = "640px"; ifrm.style.height = "480px"; document.body.appendChild(ifrm); } </script>
also check basics of the iFrame element
It is better to process HTML as a template than to build nodes via JavaScript (HTML is not XML after all.) You can keep your IFRAME's HTML syntax clean by using a template and then appending the template's contents into another DIV.
<div id="placeholder"></div> <script id="iframeTemplate" type="text/html"> <iframe src="..."> <!-- replace this line with alternate content --> </iframe> </script> <script type="text/javascript"> var element, html, template; element = document.getElementById("placeholder"); template = document.getElementById("iframeTemplate"); html = template.innerHTML; element.innerHTML = html; </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With