SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru wii's Avatar
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    720
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Validated code help (Javascript)

    Hi,

    Can anyone help me convert this code to valid XHTML?

    Below: <head>:

    <script language=JavaScript>function openppl(app,tlb,mnu,wdt,hei){window.open('http://www.mysite.com/' + app,'','toolbar=' + tlb +',location=0,status=1,menubar=' + mnu +',scrollbars=1,resizable=1,width=' + wdt + ',height=' + hei);}</script>

    Body:

    <a href="javascriptpenppl('ppl.sendarticle.asp?a=42',0,0,360,240)">popup</a>

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the deprecated language attribute into this:
    HTML Code:
    <script type="text/javascript">...</script>
    If at all possible, move the script code to an external file an reference that instead of putting the code inside the XHTML document.

    Also, a javascript: link is not very accessible. The link should open in the same window if client-side scripting is disabled:
    HTML Code:
    <a href="ppl.sendarticle.asp?a=42"
      onclick="openppl(this.href,0,0,360,240); return false">popup</a>
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    UK, London
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually popups in XHTML are not planned, hence the omission of the target attribute.

    http://www.sitepoint.com/article/sta...ompliant-world
    Chris Heilmann
    Blog | Articles | Binaries

  4. #4
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by codepoet
    Actually popups in XHTML are not planned, hence the omission of the target attribute.

    http://www.sitepoint.com/article/sta...ompliant-world
    The TARGET attribute is still there in XHTML 1.0 Transitional, just like it is in HTML 4.01 Transitional. There has never been a TARGET attribute in any Strict DOCTYPEs.
    Simon Pieters

  5. #5
    SitePoint Guru wii's Avatar
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    720
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im using a strict doctype - does that mean, that javascript links are not valid code ?

    Ill find another way of doing this then.

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They are valid, but there are accessibility problems. What if a visitor has a browser that doesn't support JavaScript, or has client-side scripting disabled for security reasons? If they click on a link with href="javascript:..." nothing happens.

    Using the option I outlined, the link will still work with client-side scripting disabled. It just won't pop up a new window. (BTW, make sure to inform your visitors clearly that clicking on the link will pop up a new window. This information should be inserted by JavaScript, since no JavaScript = no popup.)
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Guru wii's Avatar
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    720
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, on this particular site 99.5% uses IE6.0 with javascript enabled, so thats not an issue - valid code is for my own amusement, more or less...I will label the link though.

    So, it has to look like this:

    <script type="text/javascript">function openppl(app,tlb,mnu,wdt,hei){window.open('http://www.mysite.com/' + app,'','toolbar=' + tlb +',location=0,status=1,menubar=' + mnu +',scrollbars=1,resizable=1,width=' + wdt + ',height=' + hei);}</script>

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep.
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Guru wii's Avatar
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    720
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just one error left to solve:

    Line 2, column 30: document type does not allow element "script" here

    <script type="text/javascript">function openppl(app,tlb,mnu,wdt,hei){window.open

    The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

    One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).



  10. #10
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    UK, London
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you put the script in the body instead of the head of the page?
    Chris Heilmann
    Blog | Articles | Binaries

  11. #11
    SitePoint Guru wii's Avatar
    Join Date
    Sep 2004
    Location
    Denmark
    Posts
    720
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it !

    This Page Is Valid XHTML 1.0 Strict!

    I just moved the script include right above the </head> tag

    Thanks a lot for your help.


Bookmarks

Posting Permissions

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