javascripts For Your Website

Javascripts For Your WebsiteSome common things to implement in our webpage very frequently are as follows. How to implement all these I am going to tell you in this tutorial.

  1. Add To Favorite
  2. Set As Homepage
  3. Go To Top Of Page
  4. No Right Click
  5. Print Page
  6. Adding Current Date
  7. Adding Current Time
  8. Pop-Up Page Creation
  9. Closing Window
  10. Copyright Notice Updation

01.  Add To Favorite

Someone may be interested in the content of your page. Offer him/her to add the page in his/her favorite menu. To do this you have to place the following code in your page.

<a href="javascript:window.external.AddFavorite('http://www.yoursite.com/', 'Site Title');">Add to favorite</a>

Put this code where you want to show this. This script only works for IE5+ browsers.

02.  Set As Homepage

Someone may be interested to set your page as their homepage. Offer him/her to set the page as his/her homepage with the following code.

<SCRIPT LANGUAGE="JavaScript">
<A href="javascript:history.go(0)" onClick="javascript:this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.yourlink.com/');" TARGET="_self">Set As HomePage</A>
</SCRIPT>

Put this code where you want to show this. This script only works for IE5+ browsers.

03.  Go To Top Of Page

If your page is too long then always use this option. Offer him/her to go to the top of your page anytime.

<A HREF="javascript:scroll(0,0)">Go to top</A>

Put this code where you want to show this. This script works in all browsers.

04.  No Right Click

Copy & paste the code below in between your <head> and </head>.

<script language=JavaScript>
<!--
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// -->
</script>

This silent script works in all browsers.

05.  Automatic Page Print

Just copy & paste the code below where you want to show this.

<a href='javascript:;' onClick='window.print();return false'>Print this page.</a>

This script works in all browsers.

06.  Adding Current Date In Webpage

To display the current date in your webpage just copy and paste the following code where you want to show it.

<script type="text/javascript">
var d = new Date()
document.write(d.getDate())
document.write(".")
document.write(d.getMonth() + 1)
document.write(".")
document.write(d.getFullYear())
</script>

This script works in all browsers.

07.  Adding Current Time In Webpage

To display the current time in your webpage just copy and paste the following code where you want to show it.

<script type="text/javascript">
var d = new Date()
document.write(d.getHours())
document.write(":")
document.write(d.getMinutes())
document.write(":")
document.write(d.getSeconds())
</script>

This script works in all browsers.

08.  Popup Window

Sometimes we see that we click on a link & it opens up in a new popup window of some size predefined say 300x200. At first copy the code below in your <head> & </head> of the page.

<SCRIPT LANGUAGE="JavaScript">
<!--
function Start(page)
{
OpenWin = this.open(page,"CtrlWindow","toolbar=No,menubar=No,location=No,
scrollbars=Yes,resizable=No,status=No,
width=550,height=470,left=150,top=150,"); }
//-->
</SCRIPT>

Now paste the code for your link where you want to display.

<a href="javascript:void(0);" class="navlink" onclick="javascript:Start ('link.html');">Your Link</a>

This script works in all browsers.

09.  Closing Window

We might be interested to close a window with a link or a button. See the code.

Closing with button

<form>
<input type="button" value="Close Window" onClick="window.close()">
</form>

Closing with link

<a href="javascript: self.close()">Close Window</a>

This script works in all browsers.

10.  Updating Coyright Notice

This copyright notice palces the current year on the page so that copyright notices are always current. Once it's on your page there is no need to update the script.

<script language = 'JavaScript'>
<!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var today = new Date();
var year = y2k(today.getYear());
document.write(' '+year+' all rights reserved');
//-->
</script>

This script works in all browsers.


Close    To Top
  • Prev Article-Web Design:
  • Next Article-Web Design:
  • Now: Tutorial for Web and Software Design > Web Design > JavaScript > Web Design Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction