Jump to content

Window.open() To Create A Chart


davej

Recommended Posts

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

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...