document.write

Overwriting iframe's document.write

断了今生、忘了曾经 提交于 2019-12-05 20:00:54
For my own purposes ( cough lazy-loading an ad script), I am overwriting the document.write function in order to buffer the script's output, writing it to a div, and restoring the native document.write when I am done. The pseudo-code looks something like this: save off native code document.write redefine document.write eval and buffer output of script when script is done, write buffer to restore native document.write The problem happens in the bolded step - one of the lines in the ad script creates an iframe, and calls frame.document.write Stepping through Firebug, I have verified that this

How to override JavaScript function from a Firefox extension?

风流意气都作罢 提交于 2019-12-05 13:06:05
I am trying to intercept calls to document.write for all pages. Setting up the interception inside the page by injecting a script like function overrideDocWrite() { alert("Override called"); document.write = function(w) { return function(s) { alert("special dom"); w.call(this, wrapString(s)); }; }(document.write); alert("Override finished"); } Is easy and works, but I would like my extension to setup the interception for each document object from inside the extension. I couldn't find a way to do this. I tried to listen for the "load" event and set up the interception there but it also fails.

Recommended method to locate the current script?

筅森魡賤 提交于 2019-12-05 02:12:35
I am writing a script that needs to add DOM elements to the page, at the place where the script is located (widget-like approach). What is the best way to do this? Here are the techniques I am considering: Include an element with an id="Locator" right above the script. Issues: I don't like the extra markup If I reuse the widget in the page, several elements will have the same "Locator" id. I was thinking about adding a line in the script to remove the id once used, but still... Add an id to the script. Issues: even though it seems to work, the id attribute is not valid for the script element

what should I use instead of document.write for a popup

邮差的信 提交于 2019-12-04 04:25:56
问题 in my web page, I am opening a popup window and generate the HTML for the popup using JavaScript/jQuery: var site="<html> ............. </html>"; var popupWindow = window.open("","","menubar=0,scrollbars=0"); popupWindow.document.write(site); The problem is, that the popup window shows "reading" in the status bar. What should I use instead of document.write()? EDIT: document.close(); should do the work, thanks. Unfortunately, my framework may be interfering, so it's not working for me in FF.

javascript document.write() removes the html from page and display result in a blank page [duplicate]

爱⌒轻易说出口 提交于 2019-12-04 02:42:41
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JavaScript - what are alternatives to document.write? i am creating a javascript function which i want to execute after few seconds but when it executes it removes all the page content and display only that result which i am displaying using document.write() here is my javascript code. <script language="javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new

How to load third-party javascript tag asynchronously which has document.write

荒凉一梦 提交于 2019-12-03 20:43:03
问题 We give out a piece of javascript tags such as <script src="http://ours.com/some.js"></script> which site owners put on their site like http://example.com and in this javascript tag we want to dynamically include a third-party js such as which can have document.write in it, but of course if we try to include it by conventional method, var script_tag = document.createElement('script'); script_tag.type = 'text/javascript'; script_tag.src="http://third-party.com/some.js"; document.getElementById

document.write vs appendChild

僤鯓⒐⒋嵵緔 提交于 2019-12-03 08:56:45
问题 Is there a difference in load \ execution time between the following two ways of adding a script to a page ? <script> document.write('<script src=someScript.js></script>'); </script> vs this: <script> var s=document.createElement('script'); s.src='someScript.js'; document.body.appendChild(s); </script> assuming both are added at the same location on the page (before the closing body tag). Any info is appreciated! Edit: Thanks all for the comments and answers. I'm actually looking for specific

What is the best way to lazy load doubleclick ads that use document.write?

别等时光非礼了梦想. 提交于 2019-12-03 00:07:47
Ads requested via doubleclick often get served from an ad provider network that returns javascript that in turn performs document.write to place ads in the page. The use of document.write requires that the document be open, implying that the page hasn't reached document.complete. This gets in the way of deferring or lazy loading ad content. Putting such code at page bottom is helpful but doesn't do enough to lower all-important "page-loaded" time. Are "friendly iframes" the best we have? Is there any other alternative such as a clever way to override document.write that preserves the proper

document.write vs appendChild

六月ゝ 毕业季﹏ 提交于 2019-12-02 23:06:12
Is there a difference in load \ execution time between the following two ways of adding a script to a page ? <script> document.write('<script src=someScript.js></script>'); </script> vs this: <script> var s=document.createElement('script'); s.src='someScript.js'; document.body.appendChild(s); </script> assuming both are added at the same location on the page (before the closing body tag). Any info is appreciated! Edit: Thanks all for the comments and answers. I'm actually looking for specific information on differences in load time and\or execution (if there are any?). Also, I can place both

Consequences javascript can have document.write in the code?

我与影子孤独终老i 提交于 2019-12-02 17:20:03
问题 The question is about this article: https://www.html5rocks.com/en/tutorials/speed/script-loading/ They are saying this: <script src="//other-domain.com/1.js"></script> <script src="2.js"></script> Ahh, blissful simplicity. Here the browser will download both scripts in parallel and execute them as soon as possible, maintaining their order. “2.js” won’t execute until “1.js” has executed (or failed to do so), “1.js” won’t execute until the previous script or stylesheet has executed, etc etc.