simple javascript

css , java Malaysia
  • 17 years ago

    hi there,


    actualy i was wondering how to do a command that can make the current (web page displayed) to be printed???
    i've seen in many web sites... the use <form> i mean buttons to do that but i dont want buttons..... just a simple text.......


    Code:

    <a onClick="document.Print ">click here (only once) to print</a>


    the thing is i dont know the command in red is valid or not.. coz its not  working!... but when i try using
    alert('Hello')  it displays the alert box......


    can give me right code to print my document??


    thanks

  • 17 years ago

    U Can always put the javascript into its own section like below, ovbiously i have it opening a window but just add the document.print instead of open(blah blah)


    Code:

    <script LANGUAGE="JavaScript">
    <!--//
    function launch()
    {
    open('me.htm', 'tipofday', 'resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, width=300, height=300')
    }


    document.write('<p align="center"><A HREF="javascript:launch()">Click here now!</A>')
    //end hiding contents -->
    </script>



    come on people shoow me the easier way, i know there is

  • 17 years ago

    window.print


    Code:

    <a onclick="window.print()">print</a>


    hope this helps.

  • 17 years ago

    yeah thats short ..... thats what i want thanks boy.......

  • 17 years ago

    yar, the problemo with your code was that you didn't have the open and close brackets, to show that it's a function with no other parameters passed to it, so nzjonboy's code rectifies that


    (completely pointless post but hey)

  • 17 years ago

    thanks again.... fellas..

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The trouble with programmers is that you can never tell what a programmer is doing until it's too late.” - Seymour Cray