Reputation: 17
OldFunc = window.onload;
window.onload = OnLoad;
function OnLoad(){
try{
var pathName = window.location.pathname.toLowerCase();
//alert(pathName);
if( pathName.indexOf("something")!=-1)
{
OnFixFontAndTable();
alert(pathName);
}
OldFunc();
}
catch(e)
{
alert(e);
}
}
function OnFixFontAndTable()
{
//$('body').attr('style','');
document.getElementsByTagName('body').style="";
}
I would like to use that code snip to delete the body's style in a page but when I run the page, I keeps getting teh error "TypeError OldFunc is not a function"
I feed my URL address bar as "localhost:8080/pages/something.php"
Upvotes: 0
Views: 135
Reputation: 389
Well you explained it there by urself. There is no function named OldFunc in your CodeSnippet.
try
$(document).ready(OnLoad);
function OnLoad(){
try{
var pathName = window.location.pathname.toLowerCase();
//alert(pathName);
if( pathName.indexOf("something")!=-1)
{
OnFixFontAndTable();
alert(pathName);
}
}
catch(e)
{
alert(e);
}
}
function OnFixFontAndTable()
{
//$('body').attr('style','');
document.getElementsByTagName('body').style="";
}
Upvotes: 0
Reputation: 107526
Try changing your first line to:
var OldFunc = window.onload || function() {};
If window.onload
is undefined
, and you try calling it, you will get that error. The code above will assign an empty function to OldFunc
in the case where window.onload
is undefined
, so when you try calling OldFunc()
in OnLoad()
it won't fail.
Alternatively, let jQuery handle the event for you by specifying an onDomReady
event. Replace the first two lines of your code with this:
$(function() {
OnLoad();
});
Upvotes: 2