PDA

View Full Version : Force all JS to 'pause'?



djr33
11-26-2010, 05:29 AM
I had an idea for a JS bookmarklet: something to disable all JS on a page.

The reason would be to stop unexpected things from happening, especially ads with sound. I'm talking about rotating ads, not just static flash ads.

This might be useful for other reasons as well.

In PHP, $GLOBALS contains all of the active variables-- everything. By looping through the array, you could remove all of this and effectively disable most things.

My knowledge of JS isn't strong enough to find an equivalent (perhaps window. or document.?), but if someone has an idea that would work to disable all active processes, that would be great. I imagine that looping functions would cause more trouble than just unsetting all variables, but perhaps there's a way.

Or, alternatively is there any code that is guaranteed to crash JS? Or make it pause (like sleep() in PHP)?

Just attach this to a bookmarklet and it would probably be very popular.

jscheuer1
11-26-2010, 06:08 AM
The browser has this. Any particular browser(s) you have in mind?

djr33
11-26-2010, 08:03 AM
Sorry, I should be more specific:
I want to block JS at a specific time (an off button) for a particular window (or tab).

Now that I think about it the idea of crashing JS probably won't work for just a single window. It would crash for the whole browser.

Disabling JS at the browser level is very problematic because JS is useful except when it's used for ads and other things that pop up annoyingly. So disabling it for a problematic window (without having to close that window, but while keeping JS active for the other windows) would be great.


Now if there is some method available in the browser, that would be fine too. I'm using Firefox (though if this works in other browsers, I wouldn't mind knowing about that either).

jscheuer1
11-26-2010, 10:33 AM
I don't think you can disable javascript for a window. You can disable/enable javascript for the browser. Good news is that most javascript that's disabled after it's initialized will resume from where it left off once javascript is re-enabled.

In Firefox use developer's tools > Disable > Disable JavaScript > All JavaScript.

It's a toggle. I dunno what it is in FireBug. With or without either, you can always - from the native Firefox menu:

Tools > Options > Content > Enable JavaScript

It's also a toggle (a checkbox), and there's an advanced button there that lets you pick and choose among some javascript features.

djr33
11-26-2010, 08:41 PM
But you don't have any ideas about a bookmarklet that would block it for a certain window?

djr33
12-05-2010, 06:21 PM
Following up, I haven't found anything particularly useful. One method that works well is alert() and it pauses everything that's going on. At least in firefox, this still allows you to use the other windows as well. The only problem is that it pauses the entire window, including all tabs. So in order to leave a window paused, that disables all tabs; in other words, you must use separate windows rather than tabs. Aside from that, it's a perfect solution.