Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:57:40+00:00 2026-06-11T11:57:40+00:00

Is it possible to use d3.js when opening new windows? For example, I am

  • 0

Is it possible to use d3.js when opening new windows? For example, I am trying:

new_window = window.open("userpage.html");
new_window.document.write("<html><body>");
new_window.document.write("<table id=\"usertable\">");
new_window.document.write("</table>");
new_window.document.write("</body></html>");    
table = d3.select("#usertable");
console.log(table);
var thead = table.append("thead");
var tbody = table.append("tbody");
var columns = ["dataset"];

thead.append("tr")
    .selectAll("th")
    .data(columns)
    .enter()
    .append("th")
    .text(function(column) { console.log(column); return column; });

It doesn’t work and the ouput of the first console.log is

[
Array[1]
0: null
length: 1
parentNode: HTMLHtmlElement
__proto__: Array[0]
]

I think 0: null is not good.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:57:42+00:00Added an answer on June 11, 2026 at 11:57 am

    There are a few issues here:

    • I think you’re opening the new window incorrectly – generally, you either open a URL with content, or you use "" as the URL and write your content into a blank window. Opening a URL like "usertable.html" and then writing <html><body> doesn’t make sense. Finally, even with a blank window, you don’t need to write <html><body> – the browser will generally provide these nodes by default.

    • Using d3.select is going to look, by default, in the current document. In order to access the body of the newly opened window, you’ll need to pass in new_window.document – in fact, you’ll need to pass in new_window.document.body, since you can’t append anything to document without a HIERARCHY_REQUEST_ERROR.

    • I also don’t think it’s a good idea to mix D3 with document.write as you’re doing here. D3 selects nodes in the DOM, and the way you have the code now, I don’t think your table is actually a well-formed node until after you’ve tried to select it. D3 is perfectly good at inserting new DOM nodes – use it instead.

    Putting all this together yields something like this:

    var newWindow = window.open('');
    
    var newWindowRoot = d3.select(newWindow.document.body);
    
    // now do some writing with D3
    var data = [
        { foo: "Foo 1", bar: "Bar 1" },
        { foo: "Foo 2", bar: "Bar 2" }
    ];
    
    var table = newWindowRoot.append('table');
    
    var rows = table.selectAll('tr')
        .data(data);
    
    rows.enter().append('tr');
    
    var cells = rows.selectAll('td')
        .data(function(d) { return d3.entries(d); });
    
    cells.enter().append('td');
    
    cells.text(function(d) { return d.value; });
    

    Working example: http://jsfiddle.net/nrabinowitz/gQf7J/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know JavaScript can open a link in a new window but is it
Possible Duplicate: C++ can I reuse fstream to open and write multiple files? why
I'd like to be able to open another window for a user and use
Is it possible to use exceptions with file opening as an alternative to using
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If
I need a control having these features: It should be possible use it in
Is possible to use ArcSDE API in .NET(C#) ? http://edndoc.esri.com/arcsde/9.2/api/capi/dbconnects/dbconnects.htm Thanks
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
Is it possible to use JMF in Android? JMF has good functionality? I'm basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.