/    Sign up×
Community /Pin to ProfileBookmark

How do you change the ‘Stop Running Scripts’ message

I made a webpage that finds factors of numbers (I know, how exciting [YAWN]). But if you enter a number too large the internet web page crashes and a message appears:

[QUOTE]

Stop running this script?

A script on this page is causing Internet Explorer to run slowly. If it continues, your computer might become unresponsive.

[/QUOTE]

I would much rather my own personalised message to appear instead because that message may seem a bit ‘frightening’ to someone and might immediately clicked yes – do stop running the scripts

I tried using a ‘try and catch’ statement but couldn’t incorporate it.

My Code is as follows (although you may not even have to read any of it if you know a solution):

[CODE]function FindFactors(Input, Maximum){
Input2 = Input
while(Input2 <= Maximum){
try {
FactorsFound.push(“<b>The Factors of ” + Input2 + ” are:</b><p style = ‘margin: 0, 0, 25px, 0; position:relative; left:20px;’>”)
TotalFactorsFound = 0
for(i = 1; i <= Math.sqrt(Input2); i++){
Input3 = Input2/i
if(Input3 == Math.round(Input3)){
FactorsFound.push(Math.round(i) + ” * ” + Input3)
TotalFactorsFound += 2
}
}
TotalFactorsFound -= (Math.sqrt(Input2) == Math.round(Math.sqrt(Input2))) ? 1 : 0
if(TotalFactorsFound == 1){
FactorsFound.push(“The Number ” + Input2 + ” has ” + TotalFactorsFound + ” Factor”)
}else if(TotalFactorsFound == 2){
FactorsFound.push(“The Number ” + Input2 + ” has ” + TotalFactorsFound + ” Factors, Making it a <b><u>Prime Number</u></b>”)
}else{
FactorsFound.push(“The Number ” + Input2 + ” has ” + TotalFactorsFound + ” Factors”)
}
FactorsFound.push(“</p>”)
Input2++
}catch (err){
Error2()
}
}
DisplayFactors(FactorsFound, Input)
}[/CODE]

Is it even possible to do what I am trying to do. Also, I imagine other web browsers have a similar system to IE – they stopping running scripts when it becomes to much to handle, but I don’t have to worry about that for now.

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jul 09.2010 — Well it can't really be optimised, and the dialogue box can't be changed, so I think you are just going to have to warn your users about it. One change I'd make is this nevertheless. for(var i = 1, max = Math.sqrt(Input2); i &lt;= max; i++){
if(Input2&amp;#37;i == 0){
FactorsFound.push(i + " * " + Input2/i)
TotalFactorsFound += 2
}
}
TotalFactorsFound -= (max==Math.round(max)) ? 1 : 0

Also, as good practice, I'd start using local variables instead of global ones.
Copy linkTweet thisAlerts:
@Michael___authorJul 09.2010 — Thanks, it made things a little tidier. I couldn't get:
[CODE]TotalFactorsFound -= (max==Math.round(max)) ? 1 : 0[/CODE]
to work though - I'm not sure what it was?

Also, in Javascript, what are the differences between global and local variables and how would I replace the current global ones with local ones? Will it make much of a difference?

Thanks
Copy linkTweet thisAlerts:
@Declan1991Jul 09.2010 — Forget the latter then, though I thought that worked.

When you use a variable for the first time, put var in front of it. It won't make a huge difference, but it's better practice. For example.[B]var [/B]TotalFactorsFound -= (Math.sqrt(Input2) == Math.round(Math.sqrt(Input2))) ? 1 : 0
if(TotalFactorsFound == 1){
×

Success!

Help @Michael___ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...