0

Here is a div that the user clicks on:

<div id="generate2_pos" onclick="damperdesign_payload();" class="button">Generate P-Spectra</div>

This calls the damperdesign_payload() function which links it to another page. When this happens it hangs. I am sure of it hanging only on linking since I walked through the damperdesign_payload function.

So for instance in the last if/else check in that function right before the page is redirected:

if((typeof sessvars.dampertype === 'undefined') || (sessvars.dampertype == "")){
    alert("You haven't selected damper type.");
 }
else{
    //This is where it reaches, after which my page hangs.
document.location.href='spectra.html';
 }

In most cases on the first time around, the next page (spectra.html) will work properly. At the end of the website cycle, when I kept hitting back repeatedly in the program to reach to the page we are currently discussing, and then click that div again, it hangs.

Could this have to do some code in spectra.html? If so, how can I debug this if the page hangs right in between the two pages?

Louis93
  • 3,843
  • 8
  • 48
  • 94
  • Why do you have the `while(1){} ` in your code? That will cause a hang as that is an infinite loop. – jfriend00 Jan 22 '14 at 18:19
  • No that's my enforced hang. It hangs by itself even without that code. I was using that snippet to step through the function I thought was problematic. This is where I got that idea from: http://stackoverflow.com/questions/7289937/how-can-you-debug-javascript-which-hangs-the-browser – Louis93 Jan 22 '14 at 18:20
  • Get rid of that `while(1){}`. I can't possibly see how it's helping anything. If you want to break into the debugger at a particular statement, then either set a breakpoint on that line or insert a `debugger;` statement. And certainly DON'T put an infinite loop in your code and then ask here why it hangs! – jfriend00 Jan 22 '14 at 18:22
  • I'm sorry if I am not being clear. Maybe that was a shoddy way of doing manual breakpoints, but to be clear the code hangs without that `while(1){}` snippet. – Louis93 Jan 22 '14 at 18:24
  • Yes, it is a shoddy way of debugging. Use the "Edit" button and remove it from your question or you're only going to have confused people reading your message about a hang. – jfriend00 Jan 22 '14 at 18:25
  • Edited my question. Sorry about the confusion. – Louis93 Jan 22 '14 at 18:28
  • In Firebug you can click "Persist" to keep the log between page loads, and in the Chrome Dev Tools you can click "Preserve Log Upon Navigation." This will allow you to see network activity and the JS console across page loads to better determine where and when the problem is occurring. – nullability Jan 22 '14 at 18:33

3 Answers3

1

It hangs because while(1) { } is an infinite loop...

Jason
  • 51,583
  • 38
  • 133
  • 185
  • It is now clear from the OP's comments that this was only a bad debugging aid that the OP put in their code and not the actual source of their problem. – jfriend00 Jan 22 '14 at 18:36
1

First off, remove the while(1) {} loop from your code. That's a horrible way to do debugging and isn't helping you at all and is just confusing matters.

Second off, change:

document.location.href = 'spectra.html';

to

window.location.href = 'spectra.html';

as window is the location object that you should actually be using (see here for info on why).

Then, you need to sprinkle your code with relevant console.log() statements so, when it hangs (which it sounds like it only intermittently), you can try to gather clues as to what is going on. Intermittent and timing sensitive problems are notoriously hard to debug because you often can't use normal breakpoints and stepping through the code to see what's causing the problem. So, instead, you need to drop a whole bunch of breadcrumbs and then when the problem occurs you look at what the breadcrumbs tell you, try to get some clues about where the problem is occurring or what it might be and then often that leads you to put in more breadcrumb info until eventually you narrow in on what is causing the problem.

I'd suggest you generously sprinkle console.log("some unique string here") statements in both the function that changes the page and in the initialization code of the spectra.html page so you can try to figure out exactly how far it gets before hanging.

In addition, you should also be able to use the network tab in the Chrome debugger to see whether it got stuck loading some resource as it was starting to load spectra.html or whether it didn't yet start loading spectra.html.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

The developer tools that should be available in your browser (firefox or chrome) will give better insight as to what's causing the problem

Simon.
  • 1,886
  • 5
  • 29
  • 62