/    Sign up×
Community /Pin to ProfileBookmark

Javascript NOT WORKing

Strangest thing….i have a Sharepoint site where all of my pages are running javascript on them however if i attempt to add additional javascript to my main page it will not execute. and im using simple code like below. Has anyone ever experienced this before….?

window.onload = function(){
alert(“hello”);
}

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscDec 03.2010 — Is there a Javascript error elsewhere on the page? If there is, Javascript parsing and execution will be stopped so this event listener will never be applied.
Copy linkTweet thisAlerts:
@mrhooDec 03.2010 — Apparently you are either overiding an existing onload event, or your new onload is itself overwritten before the document loads.
Copy linkTweet thisAlerts:
@TcobbDec 04.2010 — Where are you adding this additional script? For that matter, where does the original script come from? Does it/them come from an external file, or is it located within the head section, or (shudder) within the body of the document? If you can give a truncated HTML and javascript example of this you probably can get a solution. But right now there is insufficient data for the folks who are willing to help you to do much more than speculate on the cause of your problem. Post an example.
Copy linkTweet thisAlerts:
@uknowmeimauthorDec 06.2010 — I wish i could give you an example but i wouldn't even want you to have to sifen through that much code. But i am simply placing this code in the heading of my page. It not only window.onload but any new code will not execute. At first i was thinking someone was playing a cruel joke on me but since im able to write script to the other pages i know it's not a joke.

To answer all of your questions

AJ NSC = NO other errors on the page and it so, they are not being thrown

mrhoo = not limited to onload event. This was just a simple example of code that should work.

Tcobb = this code is being written in the head of my document. i have some external JS files but this code is being writting directly inline. But i have tried both and neither are executing.
Copy linkTweet thisAlerts:
@KorDec 06.2010 — Apparently you have another window.onload within the other external JS files. But javascript events can not be fired more than once on the same element.

You should probably [I]add[/I] a new function on the same event. Could be:
<i>
</i>&lt;script type="text/javascript"&gt;
// START cross-browser attach events functions
function AttachEvent(obj,evt,fnc,useCapture){
if (!useCapture) useCapture=false;
if (obj.addEventListener){
obj.addEventListener(evt,fnc,useCapture);
return true;
} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
else{
MyAttachEvent(obj,evt,fnc);
obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
}
}
function MyAttachEvent(obj,evt,fnc){
if (!obj.myEvents) obj.myEvents={};
if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
var evts = obj.myEvents[evt];
evts[evts.length]=fnc;
}

function MyFireEvent(obj,evt){
if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
var evts = obj.myEvents[evt];
for (var i=0,len=evts.length;i&lt;len;i++) evts[i]();
}
// END cross-browser attach events functions

// Add a new function onload
AttachEvent(window,'load',function(){alert('hello')},false);
&lt;/script&gt;
Copy linkTweet thisAlerts:
@uknowmeimauthorDec 06.2010 — You have got to be kidding me. In the Body tag of my page i had an onload event which was stoping my script from running.
Copy linkTweet thisAlerts:
@KorDec 07.2010 — You have got to be kidding me. In the Body tag of my page i had an onload event which was stoping my script from running.[/QUOTE]
That means you've got to be kidding us. We all asked you to check that ?
×

Success!

Help @uknowmeim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...