document.write

Why won't this JavaScript (using document.open and document.write) work in Internet Explorer or Opera?

巧了我就是萌 提交于 2019-11-27 09:07:48
I desperately need some help on this one. I've created a <script> that closely parallels, and reproduces the problem of, another more complex <script> that I've written elsewhere. Here's what it does: creates an <iframe> and inserts in into a <div> on the page creates and appends a document to that <iframe>, which contains a <script> that defines a few functions (including a callback function and a function that loads an external <script> using AJAX) the latter external script is just a call to the callback function, which calls a function that creates a document and appends it to the <iframe>

JavaScript - controlling the insertion point for document.write

情到浓时终转凉″ 提交于 2019-11-27 07:18:48
I would like to create a page that runs a 3rd party script that includes document.write after the DOM was already fully loaded. My page is not XHTML. My problem is that the document.write is overwriting my own page. (which is what it does once the DOM was loaded). I tried overriding the document.write function (in a way similiar to http://ejohn.org/blog/xhtml-documentwrite-and-adsense/ ) but that doesn't cover cases where the document.write contains partial tags. An example that would break the above code is: document.write("<"+"div"); document.write(">"+"Done here<"+"/"); document.write("div>

JavaScript - controlling the insertion point for document.write

一世执手 提交于 2019-11-26 22:16:15
问题 I would like to create a page that runs a 3rd party script that includes document.write after the DOM was already fully loaded. My page is not XHTML. My problem is that the document.write is overwriting my own page. (which is what it does once the DOM was loaded). I tried overriding the document.write function (in a way similiar to http://ejohn.org/blog/xhtml-documentwrite-and-adsense/) but that doesn't cover cases where the document.write contains partial tags. An example that would break

Print / display a JavaScript variable's name instead of it's value

为君一笑 提交于 2019-11-26 18:26:05
问题 Is it possible to print / display a JavaScript variable's name? For example: var foo=5; var bar=6; var foobar=foo+bar; document.write(foo+ "<br>"); document.write(bar+ "<br>"); document.write(foobar + "<br>"); How would we print the variable's names so the output would be: foo bar foobar Rather than: 5 6 11 回答1: You can put the variables in an object then easily print them this way: http://jsfiddle.net/5MVde/7/ See fiddle for everything, this is the JavaScript... var x = { foo: 5, bar: 6,

How do I add something to my html using javascript without erasing the whole page

回眸只為那壹抹淺笑 提交于 2019-11-26 14:51:07
问题 I have a small calculator that I'm adding to my html. It has a few dropdowns to select stuff and when a person hits a submit button, I'd like to display a picture below the calculator in my html. I've tried using a javascript function with: document.write() but that clears the whole page. Is there a way that I can get a javascript function to run which only adds a picture to my page when a submit button is clicked? Here's a BASIC outline of my code with the part I'm having trouble with: <html

document.write() overwriting the document?

馋奶兔 提交于 2019-11-26 04:26:45
问题 This: function myFunction() { document.write(\"sup\"); } called in html like: <div id=\"myDiv\"> <script>myFunction();</script> </div>t adds a string sup to the myDiv div element. Which is what I want, exactly. However, this: function loadFile(uri) { var r = new XMLHttpRequest(); document.write(\"trying to open: \" + uri); r.open(\'GET\', uri, true); r.send(null); r.onreadystatechange = function() { if (r.readyState == 4) { myFunction(); } } } function myFunction() { document.write(\"sup\");

Dynamically add script tag with src that may include document.write

淺唱寂寞╮ 提交于 2019-11-26 00:46:52
I want to dynamically include a script tag in a webpage however I have no control of it's src so src="source.js" may look like this. document.write('<script type="text/javascript">') document.write('alert("hello world")') document.write('</script>') document.write('<p>goodbye world</p>') Now ordinarily putting <script type="text/javascript" src="source.js"></script> in the head works fine but is there any other way I can add source.js dynamically using something like innerHTML? jsfiddle of what i've tried var my_awesome_script = document.createElement('script'); my_awesome_script.setAttribute(

Execute write on doc: It isn&#39;t possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

狂风中的少年 提交于 2019-11-26 00:28:57
问题 I am trying to load a certain script after page load executes, something like this: function downloadJSAtOnload(){ var element = document.createElement(\"script\"); element.src = \"scriptSrc\"; document.body.appendChild(element); } if (window.addEventListener) window.addEventListener(\"load\", downloadJSAtOnload, false); else if (window.attachEvent) window.attachEvent(\"onload\", downloadJSAtOnload); else window.onload = downloadJSAtOnload; And while this script seems to execute and download