Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > HTML, XML, Javascript, AJAX
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-08-2008, 07:11 AM   #1 (permalink)
wolf99
Code Monkey
 
wolf99's Avatar
 
Join Date: Jan 2006
Location: in college (again) in rural Eire
Posts: 44
wolf99 is on a distinguished road
script tag for print page link?

Hi All

I'm working on bringing my site up to W3C accessibility standards so where I have a link to print the page that uses JS

Code:
<a href="#" onclick="window.print();return false;"><img src="images/print.png" alt="" />&nbsp;print page</a><br />
how do I add the <script> tag to this? assume i also need to use document.write, but am not familiar with js and have tried a few combinations with no luck

thanks for help
__________________
wolf99 is offline   Reply With Quote
Old 03-08-2008, 10:48 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 635
DJMaze is on a distinguished road
Code:
<img src="images/print.png" alt="" />
That's no accessibility. How would a blind man know what the image contains?

Right:
Code:
<img src="images/print.png" alt="printer" />
As for the script tag: huh? Your code is 100% valid XHTML.
More background info needed.....
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-12-2008, 10:12 AM   #3 (permalink)
wolf99
Code Monkey
 
wolf99's Avatar
 
Join Date: Jan 2006
Location: in college (again) in rural Eire
Posts: 44
wolf99 is on a distinguished road
yeah I know the empty alt"" is pretty bad, but I have the text next to the image as well so the image is like a clickable icon not an actual button link

that means if the image is not displayed and there is alt text it renders as
"print page print page" a bit confusing.

anyhoo.

I ran the site thru a accesibilty checker that checks a little bit more than is the XHTML valid.

It said JS should be inside <script> tags so that a <noscript> alternative can be presented should the user be on a platform that cannot access JS

Thing is as, I usually try to design very minimal purist code, I hate using JS and have never really learnt it bar the few copy and pastes from tutes etc

So I need to be able to present (if JS is available) a link that may print the page if clicked and (if JS not available) otherwise not show a link at all.

Not showing the link I think is the best thing for non JS users as they can still use the print command in their client and chances are they have a non-standard set up so may not want to print direct with default print settings.

phew* thanks for the input
__________________
wolf99 is offline   Reply With Quote
Old 03-12-2008, 10:18 AM   #4 (permalink)
wolf99
Code Monkey
 
wolf99's Avatar
 
Join Date: Jan 2006
Location: in college (again) in rural Eire
Posts: 44
wolf99 is on a distinguished road
came across this:

Quote:
document.write('<a href="javascript:window.print()">Print this page<\/a>');

Using innerHTML instead should make it possible to move the script outside the body and should also work in XHTML.
but don't know what they mean about the innerHTML thing, which of course would be what I need
(i'm using XHTML strict)
__________________
wolf99 is offline   Reply With Quote
Old 03-12-2008, 01:13 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
by innerHTML they mean use javascript to target an element in the page. your javascript can exist in the head. the code can get a little messy if you are writing it from scratch to support all browsers, but you could use a js library like JQuery and do it like this.

HTML Code:
<html> <head> <script type="text/javascript" src="jquery.js" ></script> <script type="text/javascript" src="myscript.js" ></script> </head> <body> <p>My Web Page</p> <div id="print_div"></div> </body> </html>
myscript.js
HTML Code:
$(document).ready(function() { $('#print_div').html('<a href="javascript:window.print()">Print this page</a>'); });
If JS is not supported, nothing will be injected in print_div.

**edited**
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 03-13-2008, 09:12 AM   #6 (permalink)
wolf99
Code Monkey
 
wolf99's Avatar
 
Join Date: Jan 2006
Location: in college (again) in rural Eire
Posts: 44
wolf99 is on a distinguished road
this only works for block level elements yeah?

no matter just being fussy.

will check if it validates.

Thanks very much folks
__________________
wolf99 is offline   Reply With Quote
Old 03-13-2008, 09:43 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
i don't understand what 'block level elements' refers to.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 03-13-2008, 11:21 AM   #8 (permalink)
wolf99
Code Monkey
 
wolf99's Avatar
 
Join Date: Jan 2006
Location: in college (again) in rural Eire
Posts: 44
wolf99 is on a distinguished road
it validates good ta again.

i mean because you need to reference an id or otherwise specify which href to apply this to

the link must be in its on <div> or <p> or other element that has properties to identify them in this way. usually refered to as block level elements because they they are usually displayed as independent "blocks" separated from other blocks by vertical space and typically contain inline elements and other block-level elements.

in HTML4 they are

* ADDRESS - Address
* BLOCKQUOTE - Block quotation
* CENTER - Centered block
* DIR - Directory list
* DIV - Generic block-level container
* DL - Definition list
* FIELDSET - Form control group
* FORM - Interactive form
* H1 - Level-one heading
* H2 - Level-two heading
* H3 - Level-three heading
* H4 - Level-four heading
* H5 - Level-five heading
* H6 - Level-six heading
* HR - Horizontal rule
* ISINDEX - Input prompt
* MENU - Menu list
* NOFRAMES - Frames alternate content
* NOSCRIPT - Alternate script content
* OL - Ordered list
* P - Paragraph
* PRE - Preformatted text
* TABLE - Table
* UL - Unordered list

u prob knew most of that anyhoo overkill. It dont matter too much now as it looks good anyhoo
__________________
wolf99 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add page support to a photo gallery script justin2008206 PHP 0 12-19-2007 04:28 PM
eBay Login Page rtcl10 PHP 2 09-06-2007 09:56 AM
hide target link rivers9 HTML, XML, Javascript, AJAX 8 08-25-2005 12:05 PM
Validating Your Pages With the W3C Markup Validator verto HTML / CSS 0 08-11-2003 06:17 PM
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM


All times are GMT -8. The time now is 08:12 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle