NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Handy Javascript Code Snips

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
9 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 06-01-2007, 04:55 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: May 2007
Posts: 23
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
????: NamePros.com http://www.namepros.com/code/334215-handy-javascript-code-snips.html
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(#defa ult#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="";
????: NamePros.com http://www.namepros.com/showthread.php?t=334215
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!docum ent.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.
__________________
DNSBL Lookup
DNVC is offline  
Old 06-01-2007, 06:20 AM   #2 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
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  
Old 06-01-2007, 07:32 AM   #3 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu 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:
????: NamePros.com http://www.namepros.com/showthread.php?t=334215
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.
Barrucadu is offline  
Old 07-21-2007, 11:18 AM   #4 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
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  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:48 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger