Link to home
Start Free TrialLog in
Avatar of ucacppw
ucacppw

asked on

How do I kill a javascript thread?

I have a centralised javascript function that is called from many different points in my javascript code.

In my centralised javascript function if a certain conditions arises I call
document.location.href= (some url)

However the javascript beyond that statement (and outside of my centralised function unfortunately) continues to run. Because the javascript is outside of the centralised function there are many different areas. Basically once I have called document.location.href I want all subsequent javascript to cease running while the page awaits refresh
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

ucacppw,

Can you modify the other script outside this function?  If so the best way is to just use return or break to not process more.  You can have a global variable (e.g. var changing = false;) and change it when you use the line.  The rest of the script would test that variable to know if it should proceed.

If you can't modify any of the other script then you will be out of luck.  If that solution doesn't work then there may be other ways but you will need to be able to modify more than just the one function.

Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of ucacppw
ucacppw

ASKER

I do not really want to modify the other script outside of the function because the function is called in many places so it would be quite a lot of work. All I want to be able to do when I detect the condition is simply prevent further execution of the javascript flow and change document.location.href. From what you have it sounds like that is not possible. Would you agree?
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol