You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example below will request the [BBC News](http://www.bbc.co.uk/news) home page and replace the contents of **div[data-entityid="container-top-stories#1"]** with the contents of the view
18
+
The example below will request the [BBC News](http://www.bbc.co.uk/news) home page and replace the contents of **div[data-entityid="container-top-stories#1"]** with the contents of our fake-news view:
19
+
20
+
_I left the express logic out for readability, you can view the actual example [here](example/server.js)_
19
21
20
22
```js
21
23
var iframeReplacement =require('node-iframe-replacement');
22
24
23
-
//replace res.render with iframe replacement version
25
+
//add iframe replacement to express as middleware (adds res.merge method)
24
26
app.use(iframeReplacement);
25
27
26
28
// create a regular express route
27
29
app.get('/', function(req, res){
28
30
29
-
// respond to this request with our fake-new content embedded within the BBC News home page
31
+
// respond to this request with our fake-news content embedded within the BBC News home page
30
32
res.merge('fake-news', {
31
33
sourceUrl:'http://www.bbc.co.uk/news', // external url to fetch
32
34
sourcePlaceholder:'div[data-entityid="container-top-stories#1"]', // css selector to inject our content into
If you pass a function as the transform property ```transform: function($, model) {}``` - the function will be called prior to rendering, allowing you to inject title tags or html attributes.
40
+
If you pass a function as the transform property ```transform: function($, model) {}``` - the function will be called prior to rendering, allowing you to inject title tags, html attributes etc.
39
41
40
42
## fake-news html
41
43
@@ -63,7 +65,7 @@ If you pass a function as the transform property ```transform: function($, model
63
65
64
66
## Auto base tag injection
65
67
66
-
To ensure the source scripts, styles and images load witin your site a base tag is automatically injected ```<base href="http://www.bbc.co.uk/news" />```.
68
+
To ensure the source scripts, styles and images load within your site a base tag is automatically injected ```<base href="http://www.bbc.co.uk/news" />```.
67
69
68
70
Because of this, you need to ensure all the links within your conent are absolute.
0 commit comments