PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > Web Site Design > HTML/CSS/Javascript
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools
Old 2-23-06, 12:54 PM   #1
satis
 
satis's Avatar
 
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
how to stop javascript execution

hi...this should hopefully be quick, but is there a javascript command to abort execution of the rest of the script? For instance...

PHP Code:
function whatever(var1){
    if(
var1 == 'abort'){
        
//command to kill program execution
    
}
    
//additional javascript commands

A much simplified example. Anyway, I'm basically for something with the functionality of php's die() function.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 2-23-06, 01:21 PM   #2
BerksWebGuy
Mod Squad
 
BerksWebGuy's Avatar
 
Join Date: Apr 2002
Location: Orlando, FL
Posts: 6,972
Reputation: 243
PHP die/exit will stop the page parsing (so nothing after that will be seen). Since javascript is on client-side, I don't think anything will stop the page from loading (unless you do a redirect).

If you're talking about breaking a loop: http://developer.mozilla.org/en/docs...atements:break
Or just put the commands in an if statement.

I'm not a javascript guru...but I guess I don't know exactly what you want to do (stop loading the page or just the script).
__________________
www.GoLightMedia.com
BerksWebGuy is offline  
Old 2-23-06, 01:28 PM   #3
satis
 
satis's Avatar
 
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
yea, I saw the break to break the loop, but I'm trying to just stop the javascript function from continueing execution. I can work around it in other ways, but that would require alot of redundant code or another function, both of which I'd like to avoid.

Basically, it's just a javascript function that can be called from multiple (dynamically generated) places, and if the data being passed into the function matches a specific value, I want to stop the function from continueing execution. I'm not really trying to stop page rendering or anything, I just don't want the rest of the code evaluated. This if for an AJAX-based page, hence why I'm trying to do all this in javascript.

Anyway, I appreciate the assistance. Worst comes to worst, I'll just rebuild the function so I don't need to kill code execution.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 2-23-06, 07:33 PM   #4
mixerson
 
Join Date: Jan 2005
Location: Northeast
Posts: 185
Reputation: 52
I'm not trying to be difficult, but what would happen if you just return from the function?

If you return all the way back to whatever triggered Javascript execution in the first place (for example, the "onload" property of the <body> tag), then Javascript execution will stop.

Or do you want to totally disable all event handlers after the condition is met?

Or do I totally misunderstand....
mixerson is offline  
Old 2-24-06, 12:38 PM   #5
satis
 
satis's Avatar
 
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
heh...you may be spot on about returning. It didn't even occur to me. I'm gonna give that a shot.

*edit* yep, that's what I was looking for. Just like me to try and figure out some hard way to do something rather than treating a function like a function.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 2-24-06, 04:47 PM   #6
mixerson
 
Join Date: Jan 2005
Location: Northeast
Posts: 185
Reputation: 52
It's funny, because I thought I might be making a really stupid suggestion. I've never used AJAX (though I'm familiar with what it does), so it occurred to me that you might be having an AJAX-specific problem that would render my Javascript experience useless.

Glad it worked out!

-- Tom
mixerson is offline  
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:06 PM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright 2000-2007 Jelsoft Enterprises Limited.