[advanced search]
30 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 06-01-2007, 04:55 AM   · #1
DNVC
New Member
 
Trader Rating: (0)
Join Date: May 2007
Posts: 5
NP$: 0.00 (Donate)
DNVC is an unknown quantity at this point
Handy Javascript Code Snips

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.

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#homep age)';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.oncontext menu=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>

These scripts works in most browsers.


Please register or log-in into NamePros to hide ads
__________________
The Shortest URL
DNVC is offline   Reply With Quote
Old 06-01-2007, 06:20 AM   · #2
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,800
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
Taken from here?
Dan is offline   Reply With Quote
Old 06-01-2007, 07:32 AM   · #3
Mikor
Resident Linux Geek
 
Mikor's Avatar
 
Name: Michael Walker
Location: East Yorkshire, England
Trader Rating: (7)
Join Date: Aug 2005
Posts: 2,408
NP$: 300.25 (Donate)
Mikor is a splendid one to beholdMikor is a splendid one to beholdMikor is a splendid one to beholdMikor is a splendid one to beholdMikor is a splendid one to beholdMikor is a splendid one to behold
Surely this:
Code:
<script LANGUAGE="JavaScript"> <A href="javascript:history.go(0)" onClick="javascript:this.style.behavior='url(#default#homep age)';this.setHomePage('http://www.YourLink.com');" TARGET="_self">Set As HomePage</A> </SCRIPT>


Should be this:
Code:
<a href="javascript:history.go(0)" onclick="javascript:this.style.behavior='url(#default#homep age)';this.setHomePage('http://www.YourLink.com');" TARGET="_self">Set As HomePage</a>

Not quite sure why you would need the script tags, as its just a link.
__________________
Me | Blog | Last.fm | F@h

archlinux User
Mikor is offline   Reply With Quote
Old 07-21-2007, 11:18 AM   · #4
Daniel
Danltn.com
 
Daniel's Avatar
 
Name: Daniel Neville
Location: Danltn.com / Nottingham, UK
Trader Rating: (65)
Join Date: May 2007
Posts: 1,177
NP$: 667.56 (Donate)
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
Ethan Allen Fund Ethan Allen Fund
http://neville.tk/bookmarkcreation.php

Bookmark creation tool there, just some simple PHP but it works on FireFox, Opera and Internet Explorer 5+
Daniel is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

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 Off
HTML code is Off
Forum Jump


Site Sponsors
Proof is in the Parking Get Me Visits Custom Logo Design
Advertise your business at NamePros
All times are GMT -7. The time now is 06:24 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0