document.write

Why use document.write?

为君一笑 提交于 2019-11-29 17:12:10
问题 I was wondering why ad's still use the document.write approach to inserting the add into the page <script language="javascript" type="text/javascript"> document.write("<script type='text/javascript' src='http://addomain/someadd.js'><\/sc" + "ript>"); </script> Why is it that I can't just put <script type='text/javascript' src='http://addomain/someadd.js'></script> In place of the ad? 回答1: A traditional script tag will block the page while it is loading and executing. A script loaded with

Alternatives to document.write

喜欢而已 提交于 2019-11-29 12:21:51
I am in a situation where it seems that I must use document.write in a javascript library. The script must know the width of the area where the script is defined. However, the script does not have any explicit knowledge of any tags in that area. If there were explicit knowledge of a div then it would be as simple as this: <div id="childAnchor"></div> <script ref... //inside of referenced script var divWidth = $("#childAnchor").width(); </script> So, inside of the referenced script, I am thinking of doing using document.write like this: <script ref... //inside of referenced script var

A Parser-blocking, cross-origin script is invoked via document.write - how to circumvent it?

本小妞迷上赌 提交于 2019-11-28 16:04:00
Google Chrome started implementing Blocking the load of cross-origin, parser-blocking scripts inserted via document.write in the main frame on slow networks, which causes the following error: A Parser-blocking, cross-origin script, http://example.org/script.js , is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. However, my web page requires loading a third party script synchronously, using document.write('<script src="..."></script>') . How to circumvent that blockade? More about that change: Design document Longer document Web

Document.write function replaces the whole page with the text

巧了我就是萌 提交于 2019-11-28 14:28:30
I am relatively new to javascript and I created a function to multiply two numbers together, but document.write replaces the whole page with the answer. I know this is what document.write is supposed to do, but just wanted an alternative. Remember, I am new to the language, so if it's possible, try to explain the answer. Thanks! <script language="javascript"> function calculate(){ var number1= document.getElementById("num1"); var number2= document.getElementById("num2"); var answer=number1.value * number2.value; document.write(answer); } </script> You already know how to use document

How can JavaScript make new page that contains more JavaScript?

天大地大妈咪最大 提交于 2019-11-28 14:10:53
I'm opening new page using JS and writing into it the HTML code, however when I try to write JS inside the new page using document.write() function it doesn't work. Apparently the main JS closes as soon as the it sees </script> which is intended for the JS of the new page that will be opened. Is there away around this? var opened = window.open(""); opened.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); opened.document.write("<html lang=\"en-US\" xml:lang=\"en-US\" xmlns=\"http://www.w3.org/1999

css not being applied to document.write text

半城伤御伤魂 提交于 2019-11-28 13:45:53
I'm writing text to a page using document.write for a Chrome extension, but the associated custom CSS isn't applied: <!DOCTYPE html> <html> <head> <title>TITLE GOES HERE</title> <link rel="stylesheet" href="css/popup.css" type="text/css" /> </head> <body> <script type="text/javascript"> ... function showFolder(folder) { console.debug('FOLDER: '+folder.title); document.write('<p>'+folder.title+'<br></p>'); } </script> </body> </html> The CSS is simple, just for debugging: p { color: red; } I can get it to work if I put the stylesheet link inside the function showFolder, but that can't be the

Alternatives to document.write

坚强是说给别人听的谎言 提交于 2019-11-28 05:40:36
问题 I am in a situation where it seems that I must use document.write in a javascript library. The script must know the width of the area where the script is defined. However, the script does not have any explicit knowledge of any tags in that area. If there were explicit knowledge of a div then it would be as simple as this: <div id="childAnchor"></div> <script ref... //inside of referenced script var divWidth = $("#childAnchor").width(); </script> So, inside of the referenced script, I am

load jQuery from external source if not loaded

我怕爱的太早我们不能终老 提交于 2019-11-27 20:18:33
load jQuery from source What I like to do is to drop my local jquery.js and have it hosted somewhere else. But what if Google is down? So let's code a fallback that uses another source if jQuery is "still" not loaded... I made this test case but it does not seem to work, maybe someone can help me out: http://jsfiddle.net/RBz4n This works fairly well (from HTML5 Boilerplate ): <!-- Grab Google CDN's jQuery. fall back to local if necessary --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> <script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs

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

对着背影说爱祢 提交于 2019-11-27 14:43:03
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 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, foobar: function (){ var that=this; return that.foo+that.bar } }; var myDiv = document.getElementById("results"

A Parser-blocking, cross-origin script is invoked via document.write - how to circumvent it?

血红的双手。 提交于 2019-11-27 09:28:12
问题 Google Chrome started implementing Blocking the load of cross-origin, parser-blocking scripts inserted via document.write in the main frame on slow networks, which causes the following error: A Parser-blocking, cross-origin script, http://example.org/script.js, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. However, my web page requires loading a third party script synchronously, using document.write('<script src="..."></script>'