File tree 5 files changed +99
-0
lines changed
5 files changed +99
-0
lines changed Original file line number Diff line number Diff line change
1
+ window . iframe = require ( './' ) ( { body : '<script type="text/javascript">alert("hi")</script>' } )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > iframe</ title >
5
+ </ head >
6
+ < body >
7
+ < script src ="demo.js "> </ script >
8
+ </ body >
9
+ </ html >
Original file line number Diff line number Diff line change
1
+ module . exports = function ( opts ) {
2
+ return new IFrame ( opts )
3
+ }
4
+
5
+ function IFrame ( opts ) {
6
+ this . container = opts . container || document . body
7
+ this . setHTML ( opts )
8
+ }
9
+
10
+ IFrame . prototype . parseHTMLOptions = function ( opts ) {
11
+ if ( typeof opts === 'string' ) opts = { html : opts }
12
+ if ( ! opts ) opts = { }
13
+ if ( opts . body || opts . head ) {
14
+ if ( ! opts . body ) opts . body = ""
15
+ if ( ! opts . head ) opts . head = ""
16
+ opts . html = '<!DOCTYPE html><html><head>' + opts . head + '</head><body>' + opts . body + '</body></html>'
17
+ }
18
+ return opts
19
+ }
20
+
21
+ IFrame . prototype . remove = function ( ) {
22
+ if ( this . iframe ) this . container . removeChild ( this . iframe )
23
+ }
24
+
25
+ IFrame . prototype . setHTML = function ( opts ) {
26
+ opts = this . parseHTMLOptions ( opts )
27
+ this . remove ( )
28
+ this . iframe = document . createElement ( 'iframe' )
29
+ this . iframe . style . width = '100%'
30
+ this . iframe . style . height = '100%'
31
+ this . iframe . style . border = '0'
32
+ this . container . appendChild ( this . iframe )
33
+ var content = this . iframe . contentDocument || this . iframe . contentWindow . document
34
+ content . open ( )
35
+ content . write ( opts . html )
36
+ content . close ( )
37
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " iframe" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " higher level api for creating and using iframes in browsers" ,
5
+ "repository" : {
6
+ "type" : " git" ,
7
+ "url" : " git@github.com:maxogden/iframe.git"
8
+ },
9
+ "engines" : {
10
+ "node" : " 0.8.x"
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ # iframe
2
+
3
+ higher level api for creating and removing iframes in browsers
4
+
5
+ ## usage
6
+
7
+ use with [ browserify] ( http://browserify.org )
8
+
9
+ ```
10
+ npm install iframe
11
+ ```
12
+
13
+ ``` javascript
14
+ var iframe = require (' iframe' )
15
+
16
+ // creates a new iframe and appends it to the container
17
+ frame = iframe ({ container: document .querySelector (' #container' ) , body: " hi" })
18
+
19
+ // completely removes previous iframe from container and generates a new one
20
+ frame .setHTML ({ body: " bye" })
21
+ ```
22
+
23
+ ## options
24
+
25
+ you can pass this into the constructor or ` setHTML `
26
+
27
+ ```
28
+ {
29
+ body: string contents for `<body>`
30
+ head: string contents for `<head>`
31
+ html: string contents for entire iframe
32
+ container: (constructor only) dom element to append iframe to, default = document.body
33
+ }
34
+ ```
35
+
36
+ you can also just pass in a string and it will be used as ` {html: 'yourstring'} `
37
+
38
+ ## license
39
+
40
+ BSD
You can’t perform that action at this time.
0 commit comments