Snippets | Nomads | Projects | Applications


Nomads | Philosophy | Index


NOMADS: | IFrame-Host | IFrame-Host-Demo | Sic et Non | IFrame-Source | HowTo


iFrameHost Dynamic Sizing for iFrames

The iFrameHost project has been developed to work where one webpage uses iFrames to embed the content of another page.
This might be to include a media player, or some web-based application from one page within the hosting page.
This can be very useful when using a content management system such as PmWiki

The principle is simple enough, but it has taken a while to develop a reliable version, due to some special requirements.

Current security features of most Web Browsers will not allow modification of the content of a page hosted within an iFrame, if that page is not hosted on the same domain, using the same port and protocol as the host webpage.

For simplicity, as a developer, the Host file has been designed to inject the Guest JavaScript file into the Guest page, which works nicely for single-site applications--as you only need to edit the Host page. However, if you wish to use Cross-Origin hosting, you will need to be able to edit the content of Both pages.

To Install -- Non-PmWiki websites

Files:

iframe_host.js & iframe_guest.js
(You should not need to modify these files for typical use.)

You will need a reference in your hosting page's html to the iframe_host.js

e.g. <script src="iframe_host.js"></script>

If your host page and guest page are both on

THEN:
iframe_host.js and iframe_guest.js must be in the same directory. the <iframe> tag in your html needs: class="BridgeFrame"

e.g. <iframe src="guest.html" class="BridgeFrame" ></iframe>

Otherwise:
the guest page MUST include a reference to a copy of iframe_guest.js

(best if on the same server as the guest page.)

the <iframe> tag in your html needs: class="BridgeFrame" you may wish to add crossorigin="anonymous" as an attribute as well

e.g. <iframe src="guest.html" class="BridgeFrame" crossorigin="anonymous"></iframe>

If the first method fails, even with same domain,port & protocol then try the second method.

To Install -- PmWiki:

Files:

Add the following lines to your {pmwiki}/local/Config.php file

## Include Code for BridgeSite - iFrame insertion tool recipe
include_once ('cookbook/BridgeSite.php') ;
## Insert the iframe_host.js script to the bottom of your Skin template.
$HTMLFooterFmt['BridgeSite'] = '<script src="$FarmPubDirUrl/iframe_host.js"></script>' ;