If you add javascript to the page and just call it, it will run on every page-load. If you want to limit to just case edit, or assign, or another, use this code:
$(function(){
// if we're not on the case page, don't do anything
if (!$('#bugviewContainer').length) return;
var myFunction = function(sCommand) {
// you can put a conditional in here if you only want to
// run your code for certain modes by looking at sCommand.
// on initial page load, sCommand will be 'load'
// on page load of the new case page, sCommand will be 'new'
// if the view of the page later changes without triggering a
// full page refresh, sCommand will specify the current action
// (i.e., edit, resolve, assign, close, reply, forward, etc.)
};
if ($('#sEventEdit').length > 0)
{
myFunction('new');
}
else
{
myFunction('load');
}
// run it when the view changes and pass in the new view:
$(window).on('BugViewChange', function(e, data) {
myFunction(data.sCommand);
});
});
If you find that your code (myFunction) is not firing on some or all types of page-loads, you can add a delay:
$(function(){
// if we're not on the case page, don't do anything
if (!$('#bugviewContainer').length) return;
var myFunction = function(sCommand) {
// you can put a conditional in here if you only want to
// run your code for certain modes by looking at sCommand.
// on initial page load, sCommand will be 'load'
// on page load of the new case page, sCommand will be 'new'
// if the view of the page later changes without triggering a
// full page refresh, sCommand will specify the current action
// (i.e., edit, resolve, assign, close, reply, forward, etc.)
// run after a delay (in milliseconds)
setTimeout(doSomeStuff, 100);
};
var doSomeStuff = function() {
// do your work here
}
if ($('#sEventEdit').length > 0)
{
myFunction('new');
}
else
{
myFunction('load');
}
// run it when the view changes and pass in the new view:
$(window).on('BugViewChange', function(e, data) {
myFunction(data.sCommand);
});
});