• Stars
    star
    215
  • Rank 180,201 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Javascript library for working with seamless iframes.

Beautiful, seamless iframes with seamless.js

A seamless iframe makes it so that visitors are unable to distinguish between content within the iframe and content beside the iframe. Seamless.js is a JavaScript library (with no dependencies) that makes working with iframes easy by doing all the seamless stuff for you automatically. Stuff like...

  • Automatically adds 'seamless' attributes to an iframe.
  • Easy communication between parent page and iframe page.
  • Auto-resizing the iframe to fit the contents of the child page.
  • Loading indicator when the child page is loading.
  • Auto failsafe to open iframe in separate window in case of error.
  • Inject CSS styles into the child pages.
  • Easily manage multiple iframes on the same page.
  • Creates a fallback for child pages that block cross-origin cookies. (Safari)
  • Allow the child page to pop out of the parent page.

Definitions

Throughout this document you will see the following definitions. It is important that you know what they mean.

  • Parent Page - The page that contains the iframe(s).
  • Child Page - The page that the iframe is referencing, hence it is a child page of the parent page.

How to use:

First, you will need to include this library in both the Parent and Child pages.

Setup

Parent Page Header

Assuming you have this library in a seamless directory, you will need to include the following in the Parent page.

<script src="seamless/build/seamless.parent.min.js"></script>

Child Page Header

You will now need to include the child version in all the child pages.

<script src="seamless/build/seamless.child.min.js"></script>

Connect

Create Parent Seamless IFrame

You can now use the following code within the Parent Page to turn your iframes into seamless iframes.

<script type="text/javascript">
  window.onload = function() {
    // Turns the iframe into a seamless iframe.
    window.seamless(document.getElementById('myiframe'));
  };
</script>

<iframe id="myiframe" src="childpage.html"></iframe>

Or, if you use jQuery, you can use it like so (jQuery is not required to use this library)...

<script type="text/javascript">
  $(function() {
    $('#myiframe').seamless();
  });
</script>
<iframe id="myiframe" src="childpage.html"></iframe>

You can also pass in options to the library like so...

window.seamless(document.getElementById('myiframe'), {
  loading: 'I am loading!!!!'
});

Or, using jQuery

$('#myiframe').seamless({
  loading: 'I am loading!!!!'
});

The following parameters are accepted.

  • loading - The text to show when the child page is loading.
    • type: string
    • required: false
    • default: 'Loading ...'
  • spinner - The url of the spinner GIF that is shown when the child page is loading.
  • showLoadingIndicator - Show or not the loading indicator.
    • type: bool
    • required: false
    • default: true
  • onConnect - Called when a child iframe has finished connecting.
    • type: function
    • required: false
    • default: null
  • styles - The styles to inject into the child page.
    • type: array of strings
    • required: false
    • default: []
  • fallback - If the fallback functionality is enabled.
    • type: bool
    • required: false
    • default: true
  • fallbackParams - Additional query params to attach to the fallback window when it is opened.
    • type: string
    • required: false
    • default: ''
  • fallbackText - A message to show below the child iframe to offer assistance if they are having problems.
    • type: string
    • required: false
    • default: ''
  • fallbackLinkText - The string to show within the 'Click here' link to open the fallback window.
    • type: string
    • required: false
    • default: 'Click Here'
  • fallbackLinkAfter - Text to add after the fallbackLinkText link.
    • type: string
    • required: false
    • default: ' to open in a separate window.'
  • fallbackStyles - An array of string styles to add to the fallback text when something bad happens.
    • type: array of strings
    • required: false
    • default: [ 'padding: 15px', 'border: 1px solid transparent', 'border-radius: 4px', 'color: #3a87ad', 'background-color: #d9edf7', 'border-color: #bce8f1' ]
  • fallbackLinkStyles - An array of string styles to add to the fallback link.
    • type: array of strings
    • required: false
    • default: [ 'display: inline-block', 'color: #333', 'border: 1px solid #ccc', 'background-color: #fff', 'padding: 5px 10px', 'text-decoration: none', 'font-size: 12px', 'line-height: 1.5', 'border-radius: 6px', 'font-weight: 400', 'cursor: pointer', '-webkit-user-select: none', '-moz-user-select: none', '-ms-user-select: none', 'user-select: none' ]
  • fallbackLinkHoverStyles - An array of string styles to add to the fallback link on hover.
    • type: array of strings
    • required: false
    • default: [ 'background-color:#ebebeb', 'border-color:#adadad' ]
  • fallbackWindowWidth - The width of the window that is opened up for the fallback.
    • type: int
    • required: false
    • default: 960
  • fallbackWindowHeight - The height of the window that is opened up for the fallback.
    • type: int
    • required: false
    • default: 800

Connect Child Page to Parent Page

Within the Child Page, you will need to now add the following code to connect the Child Page to the parent page.

<script type="text/javascript">

  // Connect to the parent page.
  window.seamless.connect();
</script>

You can also pass in parameters to this like so...

window.seamless.connect({
  container: 'div.content'
});

The following parameters are accepted.

  • url - The url of the parent page to connect to.
    • type: string
    • required: false
    • default: ''
  • container - The container for the main content on the page which determines the height of the page.
    • type: string
    • required: false
    • default: 'body'
  • update - The milliseconds that an update is created from the child to the parent.
    • type: int
    • required: false
    • default: 200
  • allowStyleInjection - If this page should allow injected styles.
    • type: bool
    • required: false
    • default: false
  • requireCookies - If the child page requires cookies (See Child iFrame Cookie Problem section)
    • type: bool
    • required: false
    • default: false
  • cookieFallbackMsg - The message to show if the cookie test fails.
    • type: string
    • required: false
    • default: 'Your browser requires this page to be opened in a separate window.'
  • cookieFallbackLinkMsg - The text to place inside the link to have them open a new window if the cookie test fails.
    • type: string
    • required: false
    • default: 'Click Here'
  • cookieFallbackAfterMsg - The text to place after the link when the cookie test fails.
    • type: string
    • required: false
    • default: ' to open in a separate window.'
  • onUpdate - Callback that is called when an update is triggered to the parent.
    • type: function
    • required: false
    • default: null
  • onConnect - Called when the parent connects to this iframe.
    • type: function
    • required: false
    • default: null

Communicate

Another big part of this library is that it enables communication to both the Child and Parent pages. This is done through the send and receive commands.

Communicate to the Child page from the Parent page.

To communicate to the child page from the parent page, you simply need to store the jQuery object that you create. You can then use it to send and receive events to the child, like so.

var child = window.seamless(document.getElementById('myiframe'));

// Send a message
child.send({
  myparam: 'This is anything you want it to be...'
});

// Receive a message
child.receive(function(data, event) {

  // Print out the data that was received.
  console.log(data);
});

Communicate to the Parent page from the Child page.

Inversely, you can easily communicate to the parent page from the child page like so...

var parent = window.seamless.connect();

// Send a message
parent.send({
  myparam: 'This is anything you want it to be...'
});

// Receive a message
parent.receive(function(data, event) {

  // Print out the data that was received.
  console.log(data);
});

Send Responses

The last way to communicate is through a 'send' response, where you can receive a response from a send command. To do this, you simply need to pass along an object to the send method with two parameters, data to contain the data, and success to be called when the resonse has been made. Then, within a receive command, you simply return the data you wish to send as the response. The code below shows this best...

Parent Page

var child = window.seamless(document.getElementById('myiframe'));

child.send({
  data: {
    mydata: 'This is a message'
  },
  success: function(data) {

    // 'data' is what was returned from the child 'receive' function.
    console.log(data);
  }
});

Child Page

var parent = window.seamless.connect();

// Receive a message
parent.receive(function(data, event) {

  // Print out the data that was received.
  console.log(data);

  // Now return something for the response.
  return {
    myresponse: "I'm listening..."
  };
});

Using with jQuery

You can also use this library with jQuery where you can call the seamless method on the iframe jQuery element like so.

$('#myiframe').seamless();

Also, within the child page, you can refer to the seamless class like so.

$.seamless

Child iFrame Cookie Problem

Some browsers (Safari) have an issue where by default they do not allow cookies within the child iframe if it is a cross-origin domain within the child iframe. This library solves this problem by creating a fallback text to prompt the user to open up the child iframe in a separate window. Although this is not ideal, it is also not malicious where it is performing actions without the user knowing and prompts them to actually open up the separate window.

This is only necessary if the child iframe requires cookies, so for that reason, this is not a default option. To turn this on, add the following parameter to the child iframe.

window.seamless.options.requireCookies = true;

More Repositories

1

jsencrypt

A zero-dependency Javascript library to perform OpenSSL RSA Encryption, Decryption, and Key Generation.
JavaScript
6,537
star
2

makemeasandwich.js

A Node.js + Phantom.js command line application that will automatically order you a sandwich from Jimmy John's. ( http://xkcd.com/149 )
JavaScript
963
star
3

meanapp

An example M.E.A.N web application with full CRUD features.
ApacheConf
162
star
4

jquery.go.js

An easy-to-use web testing and automation tool that uses the jQuery interface within Node.js to interact with the Phantom.js browser.
JavaScript
150
star
5

resourcejs

An minimalistic Express.js library that will reflect a Mongoose model onto a RESTful interface with a splash of Swagger.io love.
JavaScript
115
star
6

jquery.treeselect.js

A minimalistic jQuery hierarchy select widget used for selecting hierarchy structures in a treeview format.
JavaScript
101
star
7

drupal.api.js

An object oriented JavaScript API Library for RESTful Drupal CMS.
JavaScript
55
star
8

zombie-phantom

Provides a Zombie.js shim around the Phantom.js Headless Browser.
JavaScript
51
star
9

presentations

A list of all my presentations.
JavaScript
48
star
10

minplayer

A minimalistic, plugin-based "core" media player for the web.
JavaScript
24
star
11

dartminer

A Bitcoin miner written in the Dart language.
Dart
20
star
12

drupal.go.js

A node.js package to automate and test Drupal using the Phantom.js headless browser.
JavaScript
16
star
13

mediafront_demo

A demo Drupal 7 site to show off the mediafront module.
12
star
14

zerotomean

The example application for 0 to M.E.A.N presentation
JavaScript
10
star
15

flatiron-passport

A Passport.js integration with the Flatiron.js web framework.
JavaScript
10
star
16

groupselfie

A web application that allows you to take Group Selfies
JavaScript
9
star
17

drupaltouch

A Sencha Touch application for Drupal CMS
JavaScript
8
star
18

drupal_multimedia

A Drupal 8 with multimedia support.
PHP
7
star
19

youtube_playlist

This is an example jQuery Mobile widget for showing YouTube Playlists. Go to http://www.youtube.com/watch?v=RlrJthCmmU8 to watch the presentation.
JavaScript
6
star
20

ResultTree

A PHP class that will take a flat parent-child mapping array, and build a result tree non-recursively.
PHP
6
star
21

limelight

A PHP library for integrating with Limelight CDN
PHP
5
star
22

restPHP

A couple of simple helper classes to help in writing RESTful PHP Libraries.
PHP
5
star
23

pivotalphp

This is a GPLv3 PHP-CLI script for Pivotal Tracker
PHP
5
star
24

formiomean

An example M.E.A.N app using Angular 4 + Form.io
TypeScript
5
star
25

juckstrap

Unfortunately named static site generation utilizing Nunjucks + Bootstrap + Wintersmith.js.
JavaScript
4
star
26

cliphp

An easy to use CLI ( command line interface ) PHP class that allows for user input.
PHP
4
star
27

phptoolbox

The PHP Toolbox is a convenient way to execute and manage your PHP scripts.
PHP
3
star
28

jekyll-kickstart

A starter Jekyll site using BootStrap 3
JavaScript
3
star
29

travist.github.com

My github pages site.
HTML
3
star
30

media_feature

A Drupal 7 media feature module.
PHP
3
star
31

CachedRequest

An extension to PEAR's HTTP_Request2 class that implements extensible caching mechanisms.
PHP
3
star
32

ropemaze

The rope maze puzzle solved using brute force.
JavaScript
3
star
33

minplayer-flash

An MIT licensed, minimalistic, skinnable, plugin based Flash media player
ActionScript
3
star
34

clicpp

This is a helper class to assist with creating command line applications in C++ where you can easily gather settings for your application.
C++
2
star
35

rotating_banner_pan

A plugin for Drupal's Rotating Banner module that implements panning.
JavaScript
2
star
36

CCK

Content Construction Kit Clone
PHP
2
star
37

drupal-zombie

A presentation and examples for "Automating and Testing Drupal with Zombie.js"
JavaScript
2
star
38

pdfjs-viewer

A built bower version of PDFJS
JavaScript
2
star
39

fpManager

A plugin manager for Flash applications.
ActionScript
2
star
40

moviemate

A Chrome extension that merges functionality between YouTube Trailers and IMDB.
JavaScript
2
star
41

jquery.moreorless.js

A quick way to add "more" or "less" functionality to HTML elements using jQuery.
JavaScript
2
star
42

JQImage.js

A jQuery widget and wrapper class for working with Images.
JavaScript
2
star
43

limelight.js

A node.js application for authenticating Limelight API requests.
JavaScript
1
star
44

drupal-media-module

This is the Drupal Media module with media player integration.
JavaScript
1
star
45

generator-juckstrap

A Yeoman generator for juckstrap.
JavaScript
1
star
46

async-shell

A super simple async shell for Node.js
JavaScript
1
star