12 Annoying jQuery Functions

Angry Face

You will always come across websites that add some code in to try and stop you from doing things on there website, but the things they are trying to stop you doing are standard activities you would normally expect your be able to do.

Such as highlighting text on the page, right clicking to copy, right clicking to go to search or opening an image in a new tab. I've seen some websites that put in bits of Javascript to stop you doing these tasks. I'm not sure why they would waste time trying to stop people doing this as it's easy to get around by turning Javascript off, the only thing it does is annoy it's visitors. Then I thought about all the other annoying stuff you see with Javascript such as pop up boxes. What I decided to do just for fun is to document these annoying things and functions you will need to perform these tasks. I hope nobody will ever use these on their website but it's fun to see some of the annoying things you can do with jQuery.

Disable Right Click

Stop the visitor from right clicking on your site.

function disableRightClick(){
         return false;

Stop Browser Resize

Change the size of the browser on resize.

function alwaysKeepFullScreen(){
           window.resizeTo(1024, 768);

Auto Refresh Page

Create a function that if you call on page load will refresh the page every 60 seconds.

function refreshPage(){
     setTimeout(function(){window.location = window.location;},

Make Sure Users Meant To Close The Window

If the user closes the window display then a message to make sure they meant to.

function makeSureOfExit(){
        if(confirm('Are you sure you want to exit?')){
             return true;

        return false;

Copy Your URL To Visitors Clipboard Only IE

function copyUrlToClipboard(){
     var url = location.href;

Resize Window To Certain Resolution

Help your visitors by resizing their window for them.

function resizeWindow(){

Hop Out Of An Iframe

Make sure that this page can not be placed in an iframe.

function outIframe(){
     if (parent.frames.length > 0) { top.location.replace(document.location); }

Disable The Ctrl Key

Stop users from using the shortcut to copy and paste text.

function disableCtrlKey(){
               return false;

Remove All Error Messages

Stop error messages from displaying on the page.

function stopErrorMessages(){
         return false;

Make All Links Open In New Window

Make sure that all links of the page will open in the new window, can be very annoying.

function linksInNewWindow(){
     $("a").removeAttr("target").attr("target", "_blank");

Stop Visitors Dragging Images To Copy

function stopImageDrag(){
         return false;

Disable Scrolling

function disableScrolling(){
         $('html, body').animate({scrollTop : 0},200);
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial