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 6861991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:36:20+00:00 2026-05-27T02:36:20+00:00

Something really weird is happening, it works when I document.write() outside the window.onload =

  • 0

Something really weird is happening, it works when I document.write() outside the window.onload = function(){} But It doesn’t when I call it from inside. Please note, the table is created (I can tell because I see the source).

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>title</title>
<style type="text/css">
#chessboard{margin:0;padding:0;border:2px solid #000}
#chessboard td{margin:0;padding:0;height:44px;width:42px;border:1px solid #000;background-repeat:no-repeat}
#chessboard td.ws{background-color:#ddd}
#chessboard td.bs{background-color:#999}
#chessboard td.bp{background-image:url('./pieces/bp.png')}
#chessboard td.br{background-image:url('./pieces/br.png')}
#chessboard td.bn{background-image:url('./pieces/bn.png')}
#chessboard td.bb{background-image:url('./pieces/bb.png')}
#chessboard td.bq{background-image:url('./pieces/bq.png')}
#chessboard td.bk{background-image:url('./pieces/bk.png')}
#chessboard td.wp{background-image:url('./pieces/wp.png')}
#chessboard td.wr{background-image:url('./pieces/wr.png')}
#chessboard td.wn{background-image:url('./pieces/wn.png')}
#chessboard td.wb{background-image:url('./pieces/wb.png')}
#chessboard td.wq{background-image:url('./pieces/wq.png')}
#chessboard td.wk{background-image:url('./pieces/wk.png')}

</style>
<script type="text/javascript">
var map="",i,ii,wsbs=true;
var abc=["a","b","c","d","e","f","g","h"];

map+="<div align=\"center\"><table id=\"chessboard\" cellpadding=\"0\" cellspacing=\"0\"><tbody>";
for(i=8;i>0;i--){
map+="<tr>";
for(ii=0;ii<8;ii++){
map+="<td id=\""+abc[ii]+""+i+"\" class=\"";
if(wsbs==true)map+="ws";else map+="bs";
map+="\">&nbsp;</td>";
if(ii!=7)wsbs=!wsbs;
}
map+="</tr>";
}
map+="</tbody></table></div>";

//document.write(map); works here

window.onload = function(){
document.write(map);
}

</script>
</head>
<body>
</body>
</html>
  • 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-05-27T02:36:21+00:00Added an answer on May 27, 2026 at 2:36 am

    When you call document.write() after the page has loaded (via window.onload()), you effectively obliterate the page as it has already rendered. Instead you should set the innerHTML of some existing element on the page to the contents of map. Since you have an empty <body>, it will be safe to write to the body’s innerHTML. Otherwise, I would recommend creating a placeholder <div> inside the <body> and modifying its innerHTML instead.

    window.onload = function(){
      document.body.innerHTML = map;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something really weird is happening: when I call foo(100*1.0f), somewhere along the line that
Something really weird is happening to my Rails app. For some strange reason, jQuery
Something really weird is happening on my website, there is an image that is
Something really weird is going on with Xcode and an iPhone project I'm working
I might be missing something really obvious. I'm trying to write a custom Panel
I am probably overlooking something really simple here but I am trying to redirect
I'm doing something really simple: slurping an entire text file from disk into a
This is probably something really simple but I cant see what! Any images I
No doubt I'm missing something really simple here but I just can't see the
I'm sure I am just doing something really dumb and not seeing it but

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.