I'm not quite sure what you are asking.
If you wanted stop execution of certain code while keeping the page interactive there isn't really an easy way to do that. You could take whatever process you want to halt and then break it into a series of steps that check a flag and then continue executing or wait until the status of the flag changes by occasionally polling the flag via setTimeout
. Something like:
<button id="pause">Pause</button>
<script>
var currentStep = 0,
pauseButton = document.getElementById('pause'),
pauseSteps = false,
steps = [
function () { /* step one */},
function () { /* step two */},
function () { /* etc. */}
],
doSteps = function () {
if (currentStep < steps.length) {
if (!pauseSteps) {
steps[currentStep]();
currentStep += 1;
} else {
setTimeout(doSteps, 250);
}
}
};
pauseButton.addEventListener('click', function (e) {
var newText;
e.preventDefault();
newText = pauseSteps ? 'Resume' : 'Pause';
pauseButton.textContent = newText;
pauseSteps = !pauseSteps;
}, false);
doSteps();
</script>
If you just want to break in the debugger, you could use the debugger;
statement, it will halt execution just like you had manually set a break point in the debugger.