Modifying the DOM in a new window
So I'm opening a new window with the following code:
- scoreboardWindow = window.open("scoreboard.html","scoreboard");
-
- $("head *", scoreboardWindow.document).remove()
- $("head", scoreboardWindow.document).append("<style>\n" +
- "table {\n" +
- " font-size: 40px;\n" +
- " font-family: Candara, Verdana, Arial, sans;\n" +
- " margin-left: auto;\n" +
- " margin-right: auto;\n" +
- "}\n" +
- "tr td:first-child {font-weight: bold;}\n" +
- "tr:nth-child(odd) td:first-child {background-color: #ccc;}\n" +
- "tr:nth-child(even) td:first-child {background-color: #aaa;}\n" +
- "tr:nth-child(odd) td:nth-child(2) {background-color: #f88;}\n" +
- "tr:nth-child(even) td:nth-child(2) {background-color: #f44;}\n" +
- "tr:nth-child(odd) td:nth-child(3) {background-color: #88f;}\n" +
- "tr:nth-child(even) td:nth-child(3) {background-color: #44f;}\n" +
- "td, th, table {\n" +
- " padding: 5px;\n" +
- " border: 1px solid #000;\n" +
- " border-collapse: collapse;\n" +
- "}\n" +
- "body { width: 100%;}\n" +
- "</style>");
Originally I had the new window open blank and added all the markup programatically, but I thought I might try having it in an external file for easier maintenance. The problem is it isn't replacing the markup in the new window. That won't be a problem for this particular piece of code since I plan to remove it anyway and put it in the external file, but when I get around to modifying parts of the DOM I need to modify I will not be able to.
So, in a nutshell, if I open the window without a url, I have no problems modifying the DOM as I need, but if I open it with a url I can't modify the DOM. My testing has shown my that scoreboardWindow.document is undefined when a url is supplied, but I'm not sure why, and my google searches are not returning any useful results.
In case you need a little more information, my goal is to have this be a controller for a scoreboard window that will be fullscreened and projected using a second monitor, and I only need to support Chrome, so if there are any Chrome specific tricks, I'm all for it.