davej Posted October 6, 2011 Share Posted October 6, 2011 If you have some JS that creates a chart in another window do you worry about entering all the standard boilerplate that you would place in an HTML file? Looking at the example... http://www.w3schools.com/jsref/met_win_open.asp ...no effort is made to add any tags at all, such as <html>, <body> or DOCTYPE Is this usual practice? Thanks. Link to comment Share on other sites More sharing options...
Ingolme Posted October 6, 2011 Share Posted October 6, 2011 The W3Schools examples may be incomplete because they're trying to focus on one particular piece of code. Don't take that as a good example for building pages. Link to comment Share on other sites More sharing options...
T1000Android Posted October 6, 2011 Share Posted October 6, 2011 If you have some JS that creates a chart in another window do you worry about entering all the standard boilerplate that you would place in an HTML file? Looking at the example... http://www.w3schools...et_win_open.asp ...no effort is made to add any tags at all, such as <html>, <body> or DOCTYPE Is this usual practice? Thanks. The tags are placed where they should be placed: in the examples. I find the w3c tutorials to be awsome. Any noob can figure out that some examples are incomplete and that they need to add some tags in some places. Link to comment Share on other sites More sharing options...
davej Posted October 6, 2011 Author Share Posted October 6, 2011 So then it is convention to build all the usual entries even though "view source" will show a blank page because it is all Javascript? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 6, 2011 Share Posted October 6, 2011 Any HTML page needs the tags that define the page as an HTML page. That includes doctype, html, body, etc. A minimal page that runs Javascript should have all of those, including the Javascript code in either the head or body. Link to comment Share on other sites More sharing options...
davej Posted October 7, 2011 Author Share Posted October 7, 2011 Any HTML page needs the tags that define the page as an HTML page. That includes doctype, html, body, etc. A minimal page that runs Javascript should have all of those, including the Javascript code in either the head or body. Well, note that I'm talking about the special case where a page is temporarily created in its entirety. You can't even do a "view source" to see what is on the page because nothing is there. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 10, 2011 Share Posted October 10, 2011 All I'm saying is that if it is an HTML page, with whatever other content on it (Javascript, Flash, etc), then it needs to be a complete HTML document. If it is not a complete HTML document then it's not an HTML page and you can't really guarantee how any given browser is going to treat it. Even if you create all of the HTML elements with Javascript from another page, you should still create the html, head, body, etc elements. It's not possible to specify the doctype using Javascript, the doctype property is read-only. So if your document needs a doctype in order to be valid, and if it's not possible to specify the doctype using Javascript, then is it possible to completely generate a page using Javascript? Link to comment Share on other sites More sharing options...
davej Posted October 13, 2011 Author Share Posted October 13, 2011 It's not possible to specify the doctype using Javascript, the doctype property is read-only. So if your document needs a doctype in order to be valid, and if it's not possible to specify the doctype using Javascript, then is it possible to completely generate a page using Javascript? Oh? This doesn't work...? w = open('','_blank');w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');w.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');w.document.write('<head><title>My Page</title></head><body>');etc...? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 13, 2011 Share Posted October 13, 2011 To see if that works, check the document.doctype property. I believe that property is set only when the page loads. Use alert to print document.doctype.publicId and see if it shows the ID you specified. Link to comment Share on other sites More sharing options...
davej Posted October 14, 2011 Author Share Posted October 14, 2011 Well, for... wSched.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); the alert... alert(wSched.document.doctype.publicId); says; -//W3C//DTD XHTML 1.0 Transitional//EN Link to comment Share on other sites More sharing options...
justsomeguy Posted October 14, 2011 Share Posted October 14, 2011 Ok, then it may be fine to do it that way. Link to comment Share on other sites More sharing options...
davej Posted October 15, 2011 Author Share Posted October 15, 2011 I am happy enough with it. I finish the writes with... w.document.write('</body></html>');w.document.close();//end writes to documentw.focus(); and then later close the window with if (w && !w.closed) {w.close()}; which looks goofy but is what the Murach text suggests to use. Link to comment Share on other sites More sharing options...
davej Posted October 19, 2011 Author Share Posted October 19, 2011 Ok, I still have one question/issue -- I'm still seeing the address at the top of my window. Shouldn't the location=no option turn that off? This is in Firefox, but I could not test IE8 because I can't find where to enable JS. http://www.w3schools.com/jsref/met_win_open.asp Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2011 Share Posted October 19, 2011 Several recent browsers no longer allow you to hide the address bar. Link to comment Share on other sites More sharing options...
davej Posted October 19, 2011 Author Share Posted October 19, 2011 Several recent browsers no longer allow you to hide the address bar. Ok, Firefox 7 won't hide the address, but IE8 will. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.