SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    0 Post(s)
    0 Thread(s)

    Top margin persist after placing Javascript

    Hi everybody!

    In my webpage I have set that the left & top margins are '0' and it worked fine.

    However, after inserting of a Random Image Javascript,there is a blank space on the top.

    Site URL: Untitled Document

    Below are the html codes:


    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    margin: 0;
    padding: 0;
    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <td align="left" valign="top">&nbsp;</td>
      </tr><script language="JavaScript" type="text/javascript">
    // This script was supplied by Dave Joosten
    // For support and info go read the Tutorial at [url=]Random Images by using simple to modify JavaScript - AJAX and JavaScript - Tutorials - DMXzone.COM[/url]
    var id = 3; // Total number of images
    var ranimage = new Array(id); // Array to hold the filenames
    ranimage[0] = "japgirl.jpg";
    ranimage[1] = "japgirl2.jpg";
    ranimage[2] = "japgirl3.jpg";
    function choseRandom(range) {
    if (Math.random)
    return Math.round(Math.random() * (range-1));
    else {
    var now = new Date();
    return (now.getTime() / 1000) % range;
    var choice = choseRandom(id);
    <script language="JavaScript">document.writeln('<td' + '><img src="' + ranimage[choice] + '" height="auto" width="100%" hspace="0" vspace="0" border="0" margin: 0; ><' + '/td>');</script>
     <style type="text/css">
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    margin: 0;
    padding: 0;

    May I know what caused the problem and what is the fix please?

    Thanks for any help and advice.

    Last edited by Mittineague; Apr 12, 2011 at 19:22. Reason: reformatting bbcode tags


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts