document.write

What are alternatives to document.write?

霸气de小男生 提交于 2019-12-16 19:48:27
问题 In tutorials I've learnt to use document.write . Now I understand that by many this is frowned upon. I've tried print() , but then it literally sends it to the printer. So what are alternatives I should use, and why shouldn't I use document.write ? Both w3schools and MDN use document.write . 回答1: As a recommended alternative to document.write you could use DOM manipulation to directly query and add node elements to the DOM. 回答2: The reason that your HTML is replaced is because of an evil

Exercise with a loop in javascript

蓝咒 提交于 2019-12-14 03:32:52
问题 I need for an university exercise to display onscreen with a document.write the tree below using a kind of loop: I used at the beginning a for loop but i printed only the first row... someone can help me? This is what I tried: var numbers = [0, 1, 2, 3, 4] for (var i = 0; i <= numbers.length; i++) { if (numbers [i] == 0) { document.write(" * </br>"); } if (numbers [i] == 1) { document.write(" *** </br>"); } if (numbers [i] == 2) { document.write(" ****** </br>"); } if (numbers [i] == 3) {

How do I use document.write() to write an event unless it is already written?

跟風遠走 提交于 2019-12-13 04:50:58
问题 I've created an array containing: [Event Location, Date, Event Name]. I am using a forEach loop to iterate through each event and using document.write to print out the details. That part is going well. However, I don't want to print out the event's title every time. I want to print out the title only once and then the details beneath it. To clarify I want it to visually look something like this: Meet and Greet Boston November New York December Concord May Cincinnati October Drink Coffee Texas

Open url in same tab AND 'document.write' after

有些话、适合烂在心里 提交于 2019-12-13 01:09:44
问题 Half of my question was answered with this. I need to open another url (or replace location/href/src, whatever) in the current tab and after that inject HTML via document.write (or innerHTML , whatever) into the new page. The code will be used in a Chrome bookmarklet which will open an enhanced version of the new page. Here is what I got so far: javascript: window.open('https://stackoverflow.com/','_self').document.write('Page Booster 3000'); Any thoughts are appreciated. P.S 1: the code

String building with Javascript document.write

孤者浪人 提交于 2019-12-12 06:30:05
问题 I am trying to write a div element from javascript. I want the line written as follows, using document.write(): <div class="Square15px" onmouseover="changeColor('boxid')"></div> I call the function that writes the div element with: <script type="text/javascript"> colorPicker("box1"); </script> I have tried the document.write() method, building the string several different ways such as: function colorPicker(box) { var box = document.getElementById(box); var boxid = box.id; var AquaStr1 = '<div

javascript document.write image error

只愿长相守 提交于 2019-12-12 05:53:18
问题 I am using Flask and pass variables (image_name) to javascript to get dynamic web content. I use those variables within document.write() to display a image file. Depending on the variable image_name the required .jpg file should be loaded. This is my JS code: document.write('<img class="img-circle profile_img" ' + 'src="{{ url_for(' + "'static', filename='images/" + "'{{ image_name }}'" + ".jpg' )}}" + '" onerror="' + "this.onerror=null;this.src='../static/images/" + "'{{ image_name }}'" + "

Why am I recieving the error 'document.write can be a form of eval'?

↘锁芯ラ 提交于 2019-12-12 04:08:53
问题 This is all I've got going, but my debugger says 'document.write can be a form of eval,' and my jsonString variable prints as undefined. Any help is appreciated, thanks. function getUrlVars() { var map = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { map[key] = value; }); return map; } var jsonString = getUrlVars()['json']; document.write(jsonString); 回答1: The reason document.write can be a form of eval is because if you write a script element

Could someone explain why this document.write overwrites the entire page?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 01:03:23
问题 Here is the code; javascript function Roll() // Results: displays a randomly selected image of a 6-sided die { var roll; roll = RandomInt(1, 6); if (roll == 1) { document.getElementById("die").src = "die1.gif"; document.write("<center><p><a href='bad.html'> Enter </a></p></center>"); } else if (roll == 2) { document.getElementById("die").src = "die2.gif"; document.write("<center><p><a href='good.html'> Enter </a></p></center>"); } else if (roll == 3) { document.getElementById("die").src =

Load html contents of a given url and place exactly there (like document.write()) in JavaScript

戏子无情 提交于 2019-12-11 10:48:21
问题 I want to write a JavaScript code that load HTML contents of a given URL and place the loaded HTML code exactly where the script is placed. (maybe this looks like functionality of the iframe tag, but i dont want "iframe tag" become a medium. i just want to load the html code and place it there without adding any container or extra parent) something like this: var url = "http://example.com/"; var html = loadhtmlcontents(url); // something like simplexml_load_file($url) for php and xml document

Output Javascript document.write in XSL

房东的猫 提交于 2019-12-11 06:52:43
问题 I'm having major trouble to output a document.write() javascript through my XSL page. (It's part of a 3rd party external tracking code snippet) My desired output is: document.write('<sc'+'ript src="'+'http'+(document.location.protocol=='https:'?'s':'')+'://'+ia_link+'"></sc'+'ript>'); An this is my complete Code: <script language="JavaScript" type="text/javascript"> var url="someurl.js"; var blablabla="some-dynamic-values"; var ia_link=url+'?parameter='+blablabla; </script> <script> <xsl:text