Javascript page listener (how to run code only on specific pages)
The following code allows you to run a function when a specific page is loaded:
if(document.loaded) {
customJavascript();
} else {
if (window.addEventListener) {
window.addEventListener('load', customJavascript, false);
} else {
window.attachEvent('onload', customJavascript);
}
}
function customJavascript()
{
try
{
var title = document.title;
if (title.indexOf('Quotation Request') !=-1){Function1();}
else if (title.indexOf('Administration') !=-1){Function2();}
else if (title.indexOf('Viewing Summary') !=-1){Function3();}
else if (title.indexOf('Client details') !=-1){Function4();}
else {}
}
catch(err)
{
txt="There was an error in the custom Javascript.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
function Function1(){
}
function Function2(){
}
function Function3(){
}
function Function4(){
}
Please sign in to leave a comment.
Comments
0 comments