Jump to content
xisto Community
modstudioindia

Handy Javascript Code Snips Ready to Apply in your webpage

Recommended Posts

:P Some 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.

  • Add To Favorite
  • Set As Homepage
  • Go To Top Of Page
  • No Right Click
  • Print Page
  • Adding Current Date
  • Adding Current Time
  • Pop-Up Page Creation
  • Closing Window
  • 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.

 

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.

 

 

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.

 

 

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>.

 

 

This silent script works in all browsers.

 

05. Automatic Page Print

 

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

 

 

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.

 

 

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.

 

 

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.

 

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

 

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

 

Closing with link

 

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.

 

This script works in all browsers.

Share this post


Link to post
Share on other sites

Gee, modstudioindia, what you wrote is great! Every time I have to write a HTML page, I usually spend unnecessary time to find back a number of these scripts in other pages or on the Web. Thanks for putting that under one roof, anyway.Now, I think the last catch to solve is a number of paranoid people de-activate Javascript on their browser. It's a shame to see how good pages show up on some screens when JS is not activated. Got a recipe to solve that one ?Cheers!

Share this post


Link to post
Share on other sites

Well, there are ways to get around the people who don't have js turned on. Most of it relies upon php:

 

03: Scroll To The Top Of The Page

 

Place this right just after the <body> tag:

 

<a name="to_top"></a>
And this is your link:

 

<a href="#to_top">Click here to go to the top!</a>
06: Display Today's Date

 

This uses php:

 

 

<?  $day = date(l);  $date = date(j);  $suff = date(S);  $month = $date(F);  $year = date(Y);  echo $day . $date.$suff . $month . $year;?>
07: Display The Time

 

This uses php:

 

 

<?  $hr = date(G);  $min = date(i);  $sec = date(s);  echo $hr . ":" . $min . ":" . $sec;?>
08: Popup Window

 

This method doesn't open the window at a set height / width:

 

 

<a href="/core_files/stuff.cfm" target="_blank">Click here</a>
10: Updated Copyright Notice

 

This uses php:

 

 

<?  $this_year = date(Y);  echo "© Copyright " . $this_year . ". All rights reserved.";?>
Some items have been missed out because they can't be done with html / php (at least not to my knowledge). Till then I suggest you put the following code after the javascript:

 

<p> Unfortunately, this features requires javascript. Please enable javascript in your browser. To learn how to enable it, click <a href="buymebuyme.com" title="Follow these instructions to enable javascript!">here</a></p>
All code on mentioned on this page should be placed inside <noscript> and </noscript> tags!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.