Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How important is that bit at the top of the page..."<!DOCTYPE html PUBLIC..."

    You know, at the top of a web page in the code where it says:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    How important is it to keep that there? I ask because it breaks something I have on my site (see the "something weird to note" bit on this tutorial page: mouseover popup tutorial)

    Is it safe to take it out? For now I've commented it out like this:

    <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"-->

    Mainly so that I remember what is supposed to go there if I need to put it back...

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Its the most important piece of code in your document. Although a transitional doctype shouldn't be used at all for new pages. There are recent posts, today even, about why thats so here. Just read through some.

    Read straight for the source.....http://www.w3.org/QA/Tips/Doctype
    Last edited by teedoff; 01-21-2012 at 05:43 AM.
    Teed

  • #3
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    626
    Thanks
    51
    Thanked 67 Times in 67 Posts
    My guess is that the problem is that the img tag isn't properly closed as required of XML documents (it must end with />), so declaring the document as an XHTML document might cause problems. And, as teedoff said, that is the most important part of your HTML document because it tells the browser/client what your document is (html 4, xhtml 1, xhtml 1.1, etc.) so that it knows what to do with all the text that you are throwing at it.
    "Yeah science!"

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djh101 View Post
    My guess is that the problem is that the img tag isn't properly closed as required of XML documents (it must end with />),
    No, the image tags are closed properly.

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by teedoff View Post
    Its the most important piece of code in your document. Although a transitional doctype shouldn't be used at all for new pages. There are recent posts, today even, about why thats so here. Just read through some.

    Read straight for the source...http://www.w3.org/QA/Tips/Doctypehttp://
    That link didn't work for me...

  • #6
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by WebKitty View Post
    That link didn't work for me...
    Sorry, typo. Try it now.
    Teed

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If you take the doctype out of the web page then you put browsers into quirks mode and each browser will display the page differently making it impossible to get a consistent appearance for your page.

    The appropriate doctype to use for new web pages is

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    or of your page is experimenting with the proposed tags in the HTML 5 draft then use

    <!DOCTYPE HTML>

    All the other doctypes are either obsolete or for use with web pages on sites originally written before HTML 4 was introduced in 1997 that that are still transitioning from HTML 3.2.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    TD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    I'll try that... see what happens...

  • #9
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,371
    Thanks
    32
    Thanked 286 Times in 280 Posts
    Quote Originally Posted by WebKitty View Post
    You know, at the top of a web page in the code where it says:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    How important is it to keep that there?
    What you're looking at is a document type declaration. It's important that every HTML document have one because it causes your pages to render in "standards mode" as opposed to "quirks mode." Quirks mode is meant for compatibility with old Web sites which were not written with modern standards in mind.

    I would recommend using a <!doctype html> document type declaration rather than the one you've shown.

    Quote Originally Posted by WebKitty View Post
    I ask because it breaks something I have on my site
    I have a feeling that at least part of the problem is that you are setting the CSS properties left and width in loader.js using unitless values:

    Code:
    elem.style.left = pos;
    elem.style.width = len;
    CSS length values should have a unit specified (such as "px").

    Code:
    elem.style.left = pos.toString() + "px";
    elem.style.width = len.toString() + "px";
    You also have a div element with a style attribute that sets four CSS properties using unitless values:

    Code:
    <div style="display: none; position: absolute; z-index: 110; left: 400; top: 100; width: 15; height: 15" id="preview_div"></div>
    The code should read:

    Code:
    <div style="display: none; position: absolute; z-index: 110; left: 400px; top: 100px; width: 15px; height: 15px" id="preview_div"></div>
    (Ideally, you would put this code in a style element or an external style sheet rather than inline via a style attribute.)

    Unfortunately, those fixes do not eliminate all of the unitless values errors. I'm not sure where else you've specified such values.
    Last edited by Arbitrator; 01-21-2012 at 06:32 AM. Reason: I fixed numerous typos. Forgot to use the preview function first.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #10
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! I'll try fixing those things (I just grabbed the code from that other site--didn't really notice that stuff)


    Quote Originally Posted by Arbitrator View Post
    I'm not sure where else you've specified such values.
    (just to clarify, *I* didn't specify the values, I just copied the code from a site that provided it. I didn't go over the js code at all because I don't know js, and I didn't notice the lack of units in the div--though I should have.
    Last edited by WebKitty; 01-21-2012 at 07:46 PM.

  • #11
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've already found a few others in the .js file that I'm adding "px" to... I hope I catch them all.

    I found this:

    function showtrail(imagename,title,width,height){
    i = imagename
    t = title
    w = width
    h = height
    timer = setTimeout("show('"+i+"',t,w,h);",200);
    }

    What kind of unit does the 200 there take? is it seconds? What is the syntax?

    (thanks again for all of your help...if you get tired of all of my questions as I go through this file just let me know. Maybe someone else can take over, or I can ask somewhere else)

  • #12
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The "1" in here doesn't refer to anything that needs a unit, right?

    if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
    newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
    }


    Another conundrum:

    There are four similar to this:

    if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
    xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
    } else {
    xcoord += e.pageX;

    Dunno if I should put anything afte rthat "2" or that "0"--ideas?

  • #13
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No the 1 doesn't need units, it is comparing the return value of indexOf to -1. You wouldn't be comparing index of to 1px...

    I suggest you look some of this up, it would save you some time. Looking up setTimeout will give you the syntax, the units for the 200 are milliseconds so 1000 would be 1 second. As for the number 2, no you don't need units, however you do need to add +'px' to both xcoords.
    Code:
    if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
    xcoord = (e.pageX - xcoord - defaultimagewidth) + 'px'; // Move to the left side of the cursor
    } else {
    xcoord += e.pageX + 'px';
    I have a feeling what you may have "copied" is some really outdated code.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #14
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The setTimeout syntax also takes a function as the first parameter. Passing it a string that it then has to try to convert into a function is extremely inefficient and poor programming practice. It demonstrates that the person who wrote the script doesn't really know JavaScript.

    When you don't know JavaScript and you copy scripts from someone else who doesn't know JavaScript you can end up with a real mess.

    The best solution would probably be to find a properly written JavaScript that does what you need and replace the current script with that.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #15
    New Coder
    Join Date
    Jan 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    The best solution would probably be to find a properly written JavaScript that does what you need and replace the current script with that.
    Probably a good idea...


  •  

    Tags for this Thread

    Posting Permissions

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