Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default page

Status
Not open for further replies.

PNorman

Programmer
Feb 7, 2005
30
US
Kinda new at this so please have patience.

I created a web page and added Javascript to determine the screenwidth used by the person's browser and set the page's left, top and width properties accordingly.

Works fine but I have a few questions about this logic...
1.) Is this the way to do it or should I have a default page to determine the screenwidth and then forward the user to the appropriate page. Right now it's one page so I don't have to edit multiple pages. If I should use multiple pages what should I call them?

2.) Because of the way I have the Javascript in there my page does not validate when I enter it in the 3WC website. Does this have an impact on my rating for Search Engines?

Here's some code to show you what I mean....
Code:
<!-- Greeting -->
<script type="text/javascript">
if (screen.width <= 800)
{
document.write('<table border="0" cellpadding="18" style="position:absolute; left:50px; top:215px; width:525px">');
}
else if (screen.width >= 1024)
{
document.write('<table border="0" cellpadding="18" style="position:absolute; left:50px; top:215px; width:725px">');
}
</script>

Because I have the work table in there the validater does not recognize it.

Any help would be greatly appreciated.

 

Why resize the browser for them? Do you not think that they have their browser at the correct size for their own personal viewing pleasure?

Design/build the site to look good no matter what browser width or height is in use... then you won't have to deal with any resizing etc.

Build your site to handle a minimum size (that you choose -- maybe 800x600) and to gracefully "collapse" when viewed in smaller than the minimum size you have chosen.

If you put some comments into your javascript sections you will pass validation too:
Code:
<script type="text/javascript">
<!--
...
//-->
</script>
Hope some of that was of use to you [smile]

Cheers,
Jeff
 

1. Don't use absolute positioning. Ever. That said, once you're not "new to this" anymore, you may find a reason to use it. I'm somewhat new (3+ years) and I haven't found a need for it yet.

2. If you use percentage width instead of fixed width for tables you don't need to determine the screen width. This will reduce the use of javascript, which some users have disabled. Also, older browsers might not recognize the 'screen.width' property. Although I occasionally use code to determine screen size, I think it's usually not a good idea to do so.

3. If you want your javascript to pass through the validator, enclose it in CDATA directives, like this:
Code:
<script type="text/javascript">
  // <![CDATA[
    javascript goes here
  // ]]>
</script>
That makes the javascript invisible to the validator, which can't validate javascript anyway. In this case it probably still won't validate because the <table> tag is hidden in the javascript and therefore invisible to the validator, but as a general practice to make your site XHTML compatible for the future, you should use the CDATA directive anyway.

Mike Krausnick
Dublin, California
 
Even if the page is using an XHTML 1.1 Strict doctype, the use of comments (as I have initially posted them) is perfectly valid (since they define a valid comment structure).

I have found many uses for absolute positioning... especially when you do not have control over the HTML and have to move elements around to fulfill a design brief. I think it's fair to say that you can usually avoid using absolute positioning if you have full control of the HTML.

Just in case you were unsure about the advice being offered.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top