Back to Mobile View

Skip to Content

TUAW Deals

Quickly enable or disable JavaScript in Safari

By using "Disable JavaScript" on Safari's Develop menu, you can eliminate annoyances from some websites, without the frustration of disabling JavaScript altogether.

I'll even show you how to make a custom keyboard shortcut for it, so your fingers never even have to leave the keyboard.

The initial setup will take a few minutes, but it will be worth it when you realize the power you will wield in your fingers when you're done.

JavaScript by itself is neither good nor evil.

JavaScript is driving a car. Most people who drive cars are good folks just trying to get from Point A to Point B as easily and quickly as possible. Some people, however, are maniacs, some are drunk drivers and some are just not very good at it.

The same is true for JavaScript. Most of the time you don't even notice JavaScript, but it's working in the background to help you and the website work together. Have you ever typed something into a field and the website immediately recognized a problem? That was JavaScript. Unfortunately the analogs of "maniacs" and "drunk drivers" of the JavaScript world all seem to work in marketing. Pop-up windows? Pop-over windows? Ads that suddenly appear or slide over what you were trying to read? Also JavaScript. Those green-double-underline links or other links that show you ads when you hover over them? JavaScript.

My favorite is when I'm at a page that won't let me copy text or even right click, thinking this is some sort of "protection." The ironic part is that many of these sites (such as for music lyrics) are posting content they don't own in the first place, and then they try to use JavaScript to block you from using it. On some sites you use Safari's Reader feature, but that doesn't always work. Fortunately, you have more tools at your disposal.

Read on for more on taming JavaScript.

JavaScript Options

If you've ever been frustrated enough by JavaScript to want to disable it entirely, you may have gone to Safari's preferences » Security tab and unchecked the box next to "Enable JavaScript." I call this the "Nuclear JavaScript Option." Unfortunately, like Global Thermonuclear War, disabling JavaScript entirely turns out to be an unfeasible option. JavaScript is used for a lot of good stuff, and a lot of bad web developers haven't taken "What if JavaScript is disabled?" into consideration for some things that should be able to work without it.

We need an elegant weapon for a more civilized age. Actually, I suggest two.

My first recommendation is to install the Safari Extension JavaScript Blacklist, which blocks most of the worst offenders, including most places that use those double-green underline link ads. This works by blocking domains, which is useful for some of the largest offenders (I'm looking at you, tynt.com and Intellitxt.com), but it won't keep all the bad JavaScript stuff from happening. There's just too much out there.

Safari's Develop Menu

The first step is to enable Safari's Develop menu. To do that, go to Safari's preferences, click on "Advanced" and check the box next to "Show Develop menu in menu bar." (Note that an earlier version of this article suggested doing this via the command line using "defaults write com.apple.Safari IncludeDevelopMenu 1," which will work but is obviously not as easy.)

The Develop menu includes several handy little features, including the ability to open the current page in another browser, or change the User Agent that Safari sends (which can be handy if you want to see the iPad or iPhone version of a page).

You can see Safari's Develop menu shown in the image at the top of this article. Near the bottom you'll see an option to "Disable JavaScript," and you can see the custom keyboard shortcut that I have applied to it (⌘+ Shift + J, but you can choose a different one if you want).

Create a custom keyboard shortcut

To create that shortcut, go to System Preferences » Keyboard » Keyboard Shortcuts.

Select "Application Shortcuts" from the left column, and then click the "+" sign under the second column. You can see mine here.

Notice that I have made several shortcuts for Safari, yours may look differently than mine. That is completely OK. The important thing is to make sure that you're in the right place: Application Shortcuts, and then press the "+" key.

That will bring up a pop-up window. Choose "Safari" as the "Application" and in the "Menu Title" field type:

Disable JavaScript

You must get the spelling and capitalization exactly correct. I recommend using copy/paste of that line above.

Then choose whatever Keyboard Shortcut you want. (I chose command (⌘) + shift + J because ⌘ + J is used for Edit » Find » Jump to Selection.) Your new shortcut should look like this:

Click "Add" and switch back to Safari. In recent versions of OS X, shortcuts are immediately updated, even if the app is already running. In older versions you had to restart the app to see the shortcut.

The nice thing is the "Disable JavaScript" menu doesn't change when you enable/disable it, so you only need one shortcut. Press it once to disable JavaScript, press it again to re-enable it. Note that bookmarklets will not work while JavaScript is disabled.

What happens when you disable JavaScript depends slightly on the page. Sometimes annoyances will stop immediately. If they don't, or if an ad has already blocked your view, simply reload the page and it will load without JavaScript. When you're done reading the page, press your keyboard shortcut again and continue surfing.

Update: You can even do this in Terminal. To make ⌘ + J equal to "Disable JavaScript" do this in Terminal:

defaults write com.apple.safari NSUserKeyEquivalents -dict-add "Disable JavaScript" '@J'

© 2014 AOL Inc. All Rights Reserved.