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

  • SEARCH
  • Home
  • 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 159633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:53:37+00:00 2026-05-11T10:53:37+00:00

I have some Javascript that is opening a blank window, assigning it with a

  • 0

I have some Javascript that is opening a blank window, assigning it with a stylesheet and then writing some text to it. This is all working fine except that the content is not having the styles applied to it.

The code looks like this:

var newWindow = window.open('', 'SecondWindow', 'toolbar=0,stat=0'); var style = newWindow.document.createElement('link'); style.type = 'text/css'; style.rel = 'stylesheet'; style.href = 'styles/style.css';  newWindow.document.getElementsByTagName('head')[0].appendChild(style); newWindow.document.body.innerHTML='<p class='verystylish'>Hello world!</p>'; 

If I use the Firefox Web Developer tools to view the generated source, save that as an html file and then open the html file manually, it applies the styles correctly, so it looks as though I need to be doing something to force the browser to apply the styles or re-render the page somehow. Any suggestions?

Edited to add, the generated source looks like this:

<html>   <head>     <title></title>     <link href='styles/style.css' rel='stylesheet' type='text/css'>   <head>   <body>     <p class='verystylish'>Hello world!</p>   </body> </html> 

The problem being that no style whatsoever is assigned to the paragraph. But opening a file with the same source code renders correctly.

  • 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. 2026-05-11T10:53:38+00:00Added an answer on May 11, 2026 at 10:53 am

    A new window opens by default with the URL ‘about:blank’. Relative URL references won’t work for this reason. To change the location of the window to match the original document, call:

    newWindow.document.open(); 

    You should then write the skeleton of the document you want to the window. You can include the stylesheet now if you want, as document.write is a more reliable way of adding a stylesheet across older browsers than DOM methods. This method also allows you to write a DOCTYPE so you don’t unexpectedly end up in Quirks Mode.

    newWindow.document.write(     '<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>'+     '<html><head>'+     '  <link rel='stylesheet' href='styles/style.css'>'+     '</head><body>'+     '</body></html>'+ ); newWindow.document.close(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use API hooking. Hooking NtCreateFile and a few other calls… May 11, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer ~(x & 0) x & 0 will always result in… May 11, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer I had the bright idea to dig through Reflector to… May 11, 2026 at 5:42 pm

Related Questions

I'm opening a new browser window from my site for some of the members.
Developing server side code i finally got my eyes X-crossed trying to write -
I'm trying to override a few CSS selectors that are causing problems in IE6
I have particular division in my web page. i want to print that div

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.