Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

document.write in prebid.js

Open sgagnierH opened this issue 8 years ago • 5 comments

Type of issue

feature request

Description

We need to get rid of all document.write over our pages, but there is one laying within prebid.js. It seems to only relates to native ads, but still, it's fairly easy to avoid this.

Steps to reproduce

module: exports.insertHtmlIntoIframe

exports.insertElement(iframe, document, 'body');

iframe.contentWindow.document.open(); iframe.contentWindow.document.write(htmlCode); iframe.contentWindow.document.close();

Could be possibly be as easy as: iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(htmlCode);

sgagnierH avatar Jul 16 '18 17:07 sgagnierH

@sgagnierH Have you tested this in IE 11, Safari 9+ and Edge ?

jaiminpanchal27 avatar Jul 18 '18 13:07 jaiminpanchal27

The code you posted is not equivalent unfortunately. The document.write method importantly preserves the DOM of the existing document (if it's already open) before writing content vs setting the iframe src will destroy any other content.

mkendall07 avatar Jul 18 '18 14:07 mkendall07

@jaiminpanchal27 No I did not tested it, it's a kinda hint.

@mkendall07 If you look at the code in place, you'll see that it creates the iframe just before the document.write, so there's nothing in it to be lost.

sgagnierH avatar Jul 18 '18 14:07 sgagnierH

cool, in that case it's ok as long as it's proven to work in the target browsers (modern + ie11 )

mkendall07 avatar Jul 18 '18 14:07 mkendall07

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 01 '18 14:08 stale[bot]