Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
External *.js file - Multiple onLoad Functions
Old 01-29-2010, 09:05 PM External *.js file - Multiple onLoad Functions
Average Talker

Posts: 15
Trades: 0
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.
FriedSushi87 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to External *.js file - Multiple onLoad Functions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14925 seconds with 12 queries