Quote:
Originally Posted by pizzipie
Using Ubuntu 20.04
I am trying to indent a line to center it on the page. I am using document.write() to do this:
Code:
<script type="text/javascript" >
document.write("      Referred By: "+document.referrer);
document.write(" This file: "+document.location);
document.write(" Last Modified: "+"<?php echo $lastModifiedDatetime; ?>");
document.write(" <hr style='width:80%;' </style>");
</script>
|
Using whitespace characters for formatting HTML documents is a losing proposition...
You mention spaces and tabs in your title which does not work at all except inside
<pre>...</pre> tags
You then show HTML entities
and
  in your example code, which are rendered "correctly" but still not really what you intended, which is to
center the line...
Quote:
Originally Posted by pizzipie
All these  's and 's don't do anything after about a few spaces. I've tried * and it is no different. As you can see on the screenshot the line beginning with "Referred By:" Should be further to the right by more than a few spaces.
I sure everyone wonders why the Javascript coders haven't written a function to do this.
|
I disagree, "Referred by:" looks to be about
6-ems from the left side, assuming no other CSS rules were inherited. And the others look about right for the example given, except for this which is obviously invalid markup:
Code:
document.write(" <hr style='width:80%;' </style>");
What is it that you expect, and how does it differ from the example shown?
Quote:
Originally Posted by pizzipie
I sure everyone wonders why the Javascript coders haven't written a function to do this.
|
They have not done that because it is not the function of javascript to render the page. What you need is a simple CSS rule, or two.
I would strongly suggest avoiding use of whitespace to control formatting for anything other than single spacings between text or other elements where that is natural and most convenient. If you want to
center that content as your question states, use a CSS
style="text-align:center" attribute on the enclosing paragraph or other parent element and forget all those spaces which cannot actually center the line anyway, and will always be problematic to maintain.
But all of this makes me wonder why you are even using javascript to write this content into the page...? You are obviously generating this all on the server as indicated by the PHP code, so why not just write it out as well formed HTML and be done with it? I suspect that you may be using javascript because of some misperception that it is the way to control the layout, which is obviously incorrect. If so, then it would be helpful to yourself and others if you gave a more complete description of the problem you are actually trying to solve so we can arrive at an appropriate solution.