简体   繁体   中英

Get iframe from contained element

I have a node from inside an iframe, and I need to get the iframe that contains the node. The JS code is executing in the document that's containing the iframe, but within the function that needs to find the iframe element I've only got the contained node.

Try this example Or click on below link:

https://www.npmjs.com/package/node-iframe-replacement

var iframeReplacement = require('node-iframe-replacement');

// add iframe replacement to express as middleware (adds res.merge method) app.use(iframeReplacement);

// create a regular express route app.get('/', function(req, res){

// respond to this request with our fake-news content embedded within the BBC News home page
res.merge('fake-news', {
    // external url to fetch
   sourceUrl: 'http://www.bbc.co.uk/news',
   // css selector to inject our content into
   sourcePlaceholder: 'div[data-entityid="container-top-stories#1"]',
   // pass a function here to intercept the source html prior to merging
   transform: null
});

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM