JAVASCRIPT
Let's
get our feet soaked right at the start. OK?
Here's
an easy way to password protect a page on your website. It's
easy... just copy and paste the code. And you know how to do that, right?
CLICK
HERE to see.
And
CLICK HERE for the code/script.
That
was easy, wasn't it?
How
about one more password protect...
CLICK
HERE to see. (The password is "WHAT")
And
Now the script:
<script language="Javascript">
<!--
var password = prompt("Enter
in the password")
if (password == "Pick One")
{
alert("Welcome!")
location = "protected.html"
}
else {
location = "oops.html"
}
//-->
</script>
In the above code,
"Pick One" is the password and "protected.html" is the name of the password-protected
page. (Substitute your own password and URL when you use this script.)
If visitors enter the correct password, they will forward to "protected.html";
if they enter an incorrect password, they'll hit the page called "oops.html."
As stated, this shouldn't
be used as a substitute for true security, but it isn't bad in a pinch.
It works nicely for, say, an area of your site reserved for family members
only.
If you do use this
code to protect a page or directory, you might want to keep search engines
from listing it. Place this tag in the HEAD section of your protected page:
<meta name="robots"
contents="noindex">
Of course, it's possible
for someone clever enough to get the password right from the source code.
Later, we'll tackle a script that will keep them from viewing the source.
NO
RIGHT CLICK
Let's
do another. NO RIGHT CLICK. This next
one you should put into use right away. I'm going to give you two different
ones. These get placed in the <HEAD> of your web page. First, the easy
one:
<SCRIPT>function click()
{if (event.button==2) {alert('Your Warning Message Line 1 here\nYour Warning
Message Line 2 here\nYour Warning Message Line 3 here\nYour Warning Message
Line 4 here');}}document.onmousedown=click// - -></SCRIPT>
Now,
the longer one:
This script works
in Internet Explorer and Netscape 6:
<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Begin
function right(e) {
var msg = "Right-clicking is
not possible in this document.";
if (navigator.appName == 'Netscape'
&& e.which == 3) {
alert(msg);
return false;
}
else
if (navigator.appName == 'Microsoft
Internet Explorer' &&
event.button==2) {
alert(msg);
return false;
}
return true;
}
document.onmousedown = right;
// End -->
</SCRIPT>
Users will still
be able to view the source from the browser menu (though not many will
be persistent enough to figure that out), but you can sort of hide your
source code there too. Just start your page with a couple of screens of
blank lines and hide the code below the visible window. That will fool
most people, especially if you include some bogus code right at the top:
<phtml/unlock
code=retrieve:"secure-bin/B23"; print=doc:"B23">
This is total nonsense,
but if you tried to view the source code and only saw that, with nothing
but white screen beneath it, wouldn't you be fooled?
STATUS
BAR SCROLLING MESSAGE
How
about a custom scrolling message?
CLICK
HERE to see the example.
And here's the code:
<!-- TWO STEPS
TO INSTALL WRITE AND SLIDE:
1. Paste the coding
into the HEAD of your HTML document
2. Copy the onLoad
event handler into the BODY tag -->
<!-- STEP ONE:
Copy this code into the HEAD of your
HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many
more are available
free online at -->
<!-- The JavaScript Source!!
http://javascript.
internet.com -->
<!-- Begin
var Message="Yet another simple
scroll from TJS!
You could
have done it!!";
var place=1;
function scrollIn() {
window.status=Message.substring(0,
place);
if (place >= Message.length)
{
place=1;
window.setTimeout("scrollOut()",300);
} else {
place++;
window.setTimeout("scrollIn()",50);
}
}
function scrollOut() {
window.status=Message.substring(place,
Message.length);
if (place >= Message.length)
{
place=1;
window.setTimeout("scrollIn()",
100);
} else {
place++;
window.setTimeout("scrollOut()",
50);
}
}
// End -->
</SCRIPT>
<!-- STEP TWO: Add this onLoad
event handler
into the BODY tag -->
<BODY onLoad="scrollIn()">
<p><center>
<font face="arial, helvetica"
size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The
JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.09 KB
-->
DANCING
LINKS?
CLICK
HERE to see the example.
CLICK
HERE to see the code.
Browser
Drop?
Here's a good one for
a personal site. You do have one of those don't you? I use mine just to
play around...
CLICK
HERE
Setting
The HomePage
Here's the easy script.
Works in IE 4 and above. Won't cause errors in Netscape though. Place in
the BODY...
<!--[if IE]>
<a HREF
onClick="this.style.behavior='url(#default#homepage)';
this.setHomePage('http://www.boogiejack.com');">
Click here to make Boogie Jack's
your start page!</a>
<![endif]-->
BLOCK
ERRORS
Here's an important
one to put in your pages. It will block any errors in script syntax that
may be laying dormant in your pages. Just a precaution...
<script language="JavaScript">
// Source: CodeFoot.com
function blockError(){return
true;}
window.onerror = blockError;
</script>
WRITING
THE ACTUAL DATE
Want to get a visitor
to order by a certain date or she doesn't get the bonuses? Here's the script.
Place it wherever you want the display. (BODY)
Order
Before
<SCRIPT LANGUAGE="Javascript">
<!--
// Specify names of days:
var dayNames = new Array("Sunday","Monday","Tuesday",
"Wednesday", "Thursday","Friday","Saturday");
// Specify names of months:
var monthNames = new Array("January","February","March","April","May","June",
"July", "August","September","October",
"November","December");
var now = new Date();
var thisday = dayNames[now.getDay()
+2];
var thismonth = monthNames[now.getMonth()];
var thisdate = now.getDate();
var thisdate=thisdate + 2;
var thisyear = now.getFullYear();
document.write(thisday + ",
" + thismonth + " "
+ thisdate + ", " + thisyear);
// -->
</SCRIPT>
and Get
6 Bonuses FREE!
And here are more
formats for writing the dates
display dates formats
dd/mm/yy
<script language="JavaScript"><!--
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0'
+ d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0'
+ m : m;
var yy = date.getYear();
var year = (yy < 1000) ?
yy + 1900 : yy;
document.write(day + "/" + month
+ "/" + year);
//--></script>
date month year
<script language="JavaScript"><!--
function makeArray() {
for (i = 0; i<makeArray.arguments.length;
i++)
this[i + 1] = makeArray.arguments[i];
}
var months = new makeArray('January','February','March',
'April','May','June','July','August','September',
'October','November','December');
var date = new Date();
var day = date.getDate();
var month = date.getMonth()
+ 1;
var yy = date.getYear();
var year = (yy < 1000) ?
yy + 1900 : yy;
document.write(day + " " + months[month]
+ " " + year);
//--></script>
JAVA
SCRIPT MENU
Here's a very easy menu
even for beginners. But it's way cool. See what you think. Remember how
to get the code?
CLICK
HERE for the menu.
Ready for even more?
Let's go to the next page...
|