I'm trying to learn how to combign all of my javascripts into one file and linking to it externally, but for some reason it won't work.
Any insight?
Code:
// JavaScript Document
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(disable1);
addLoadEvent(StarDate);
addLoadEvent(preload);
function disable1() {
document.onselectstart = function() {return false;} // ie
document.onmousedown = function() {return false;} // mozilla
document.oncontextmenu = function () {return false; //context menu (right click)
}
//preloading script
function preload()
{
//mouseover buttons
button1on = new Image();
button1on.src = "images/home2.gif";
button2on = new Image();
button2on.src = "images/education2.gif";
button3on = new Image();
button3on.src = "images/hobbies2.gif";
button4on = new Image();
button4on.src = "images/goals2.gif";
button5on = new Image();
button5on.src = "images/links2.gif";
button6on = new Image();
button6on.src = "images/experience2.gif";
button7on = new Image();
button7on.src = "images/red2.gif";
button8on = new Image();
button8on.src = "images/purple2.gif";
//mouseout buttons
button1off = new Image();
button1off.src = "images/home1.gif";
button2off = new Image();
button2off.src = "images/education1.gif";
button3off = new Image();
button3off.src = "images/hobbies1.gif";
button4off = new Image();
button4off.src = "images/goals1.gif";
button5off = new Image();
button5off.src = "images/links1.gif";
button6off = new Image();
button6off.src = "images/experience1.gif";
}
//rollover button functions
function img_act(imgName) {
{
imgOn = eval(imgName + "on.src");
document [imgName].src = imgOn;
}
}
function img_inact(imgName) {
{
imgOff = eval(imgName + "off.src");
document [imgName].src = imgOff;
}
}
// This is a script to Create a Stardate and Print.
function StarDate() {
var Now = new Date()
var NowTime = Now.getTime()/1000
var Day = Now.getDate()
var Month = Now.getMonth()+1
var Year = Now.getYear();
if (Year < 2000) Year = Year + 1900
if (Year<1000) { YearDif=Math.abs(Year-87) }
if (Year>1000) { YearDif=Math.abs(Year-1987) }
SDYear=40000+(YearDif*1000)
YearStart = new Date(Year,0,1,0,0,0)
var YearStartTime= YearStart.getTime()/1000
Days=(NowTime-YearStartTime)/86400
if (Days>=183) { SDYear=SDYear+1000
SDDays=(Days*(1000/365))-500 }
if (Days<183) { SDDays=500+(Days*(1000/365)) }
StarDate=Math.floor((SDYear+SDDays) * 10 + .5) / 10
// I've disabled printing of the stardate.
// Must find a way to print the string StarDate in Document
// document.write('<center>'+'Stardate '+StarDate+'</center>')
}
then
Code:
<script language="text/JavaScript" src="javascript.js"></script>
Now effectively it should disable the context menu, though it's not doing it. What am I doing wrong?
I'm calling on three functions to run upon page load, one disabling right click, one preloading images, and the other is calculating a date for later injection into the HTML document. The fourth function isn't called upon until the mouseover event occurs.
|