Unstoppable Domains

Handy Javascript Code Snips

Spaceship Spaceship
Watch

DNVC

Established Member
Impact
1
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.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Taken from here?
 
0
•••
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.
 
0
•••
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back