jaylab2
asked on
How can i execute a javacript after success of another
Hello i do have these functions
I do need to call this function egnyt_track(pixel, val, cny,type ,process,name) on onclick event and need to be sure that _gaq.push(['_trackEvent',t ype, process, name]); is executed after egnyt_facebook(pixel, val , cny); this and after all these executed i do need to redirect to certain page and if i need to know if i can delay a normal <a href=""> combined with onlclick event not to redirect before executing the function anyone can help me sorting this out with an example based on the script above.
function egnyt_facebook(pixel,val, cny) {
var cd = {};
cd.value = val;
cd.currency = cny;
_fbq.push(['track',pixel, cd]);
}
//combine facebook and google
function egnyt_track(pixel, val, cny,type ,process,name){
egnyt_facebook(pixel, val , cny);
_gaq.push(['_trackEvent',type, process, name]);
window.location='';
}
I do need to call this function egnyt_track(pixel, val, cny,type ,process,name) on onclick event and need to be sure that _gaq.push(['_trackEvent',t
ASKER
So what's callback function is used for ? i am new into this !
I think I should first clarify that there are situations where javascript would not be synchronous and I only know of that to be the case with ajax, otherwise javascript runs line by line and only after the previous line completes. a callback function is a technique and the same thing can be accomplished without using a callback.
for example with a callback you could do
Without callbacks I could do
for example with a callback you could do
function doMoreStuff(myString) {
alert(myString)
}
function processMyData(func) {
//do something
func('this is a test');
}
//i could pass a function to a function
processMyData(doMoreStuff);
Without callbacks I could do
function doMoreStuff(myString) {
alert(myString)
}
function processMyData(func) {
//do something
return true;
}
if (processMyData()===true)
{
doMoreStuff('success');
//do other stuff, call other functions
}
else
{
alert('fail');
}
ASKER
Thank you for your reply but can you give example on my script so it will help understand more.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
you could then have a javascript function to run code before changing window.locationOpen in new window