disable the function of clicking on links underneath css/jquery popups on mobile devices

After successfully creating a simple popup using CSS and jQuery, I encountered an issue where links underneath the popup can still be clicked. This problem arises since the click box for some of the links in the popup is small, making it easy to accidentally click next to them and activate the link underneath.

I am currently working on a site called taxslayerplayer.com, and if you view it on an Android device, you'll see exactly what I mean. This issue is not exclusive to my site; I have noticed it on many other websites while browsing on my phone as well.

If anyone has any suggestions or pointers on how to prevent this from happening, I would greatly appreciate it. Thank you!

Answer №1

If you're looking for a solution that works on mobile devices, one approach could be to check if a pop-up is currently visible. If it is, then simply prevent the default behavior of links by returning false in the click-handler:

$('a').filter(
    function(){
        return !$(this).closest(popupSelector).length;
}).on('click', function(e){
    if ($(popupSelector).is(':visible')) {
        return false;
    }
    else {
        // handle links as usual
    }
});

Another option is to use a variable like popupIsShown. Initialize it to false on DOMReady, update it to true when the pop-up is displayed, and set it back to false when hidden. This way, the conditional check becomes more efficient:

$('a').filter(
    function(){
        return !$(this).closest(popupSelector).length;
}).on('click', function(e){
    if (popupIsShown) {
        return false;
    }
    else {
        // handle links as usual
    }
});

Answer №2

To avoid pop-ups, ensure to use a boolean value and set it as false. This method has been tested and proven effective.

Update: I have verified the solution provided by David.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble with transferring JSON data using jQuery AJAX

I've set up an AJAX request to send JSON data: $(function() { var json = [{"id":"1", "area":"south"}, {"id":"2", "area":"north"},{"id":"3", "name":"east"},{"id":"1", "name":"west"}]; jQuery.ajax({ url: "index.php", type: ...

Tips for creating slanted div borders

I am working on a project where I have 4 divs serving as background colors. I want to create slanted bottom borders similar to the design in this image: Below is the code I currently have: <html> <head> <style> html, body { height: 200% ...

How to Toggle Div Visibility with AngularJS ng-show and ng-click

In order to eliminate error messages, I decided to clear the field with a button click. This approach successfully removed the error in my initial test. <div class="errorPopup" data-ng-click="runner.Name = null" data-ng-show="mainForm.name.$error.pat ...

Trouble with Bootstrap Popover's visibility

My current setup involves a popover that is not initializing properly. The code I am using is shown below: HTML: <div data-toggle="popover" data-placement="bottom" data-content="xyz">...</div> JavaScript: $(function () { $('[data-t ...

"Troubleshooting AmCharts: How to Resolve Missing Data on Graphs/Implementing AJAX for AmCharts Data Visualization/Querying a Database to Dynamically

After writing some HTML and JavaScript code, I'm trying to set up an amcharts plot. To do this, I fetch data from a database using PHP, convert it into JSON format, and then pass it to the graph for display. The issue arises when I try to assign the ...

Google Fonts are displaying in a bold style even when the bold property is not set

I need assistance with an issue involving emails going from Salesforce to Outlook 365. Here is the HTML code snippet: <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css"> <style> body ...

Guide on embedding a hierarchy triangle in an email with HTML

I am looking to include a hierarchy triangle in an email generated by my webpage. This triangle should reflect the data from the page, including the number of activities, appointments, proposals, and deals. Specifically, I want it to display: Top of the tr ...

Dynamically fetch data using Ajax with Qtip

I've experimented with the Qtip $the_tooltip= "TEST\nTEST2"; echo "<td id=25 title=".$the_tooltip." > I have this $(document).ready(function () { $('[title!=""]').qtip(); }) It's working well. I came acros ...

Troubleshooting Problem with $.ajax Call in jQuery Full Calendar (Using Static Events Upon Page Load)

Currently, I am utilizing Yii along with the FullCalendar widget in a view of CalendarController. When the widget is called, it retrieves existing events from the database and displays them within the FullCalendar. In addition to this, I have implemented a ...

Retrieve the data from the second event in the ajax response and return its value

Can this be achieved? I have successfully retrieved the desired value from an ajax result, but now I need that value to be returned by another event. Currently, it is returning as 'undefined'. Please check out my code below. Any suggestions? Than ...

What is the best way to apply opacity to a div without affecting the background image?

Is there a way to apply opacity to a div without affecting the background image? When an ajax request is made, a certain class is added to a specific div, causing all its contents to have reduced visibility. However, this also affects the background ajax ...

Sending form data without interrupting the user interface by using asynchronous submission

Using jQuery version 1.7.2, I am currently using the submit() method to send a form via POST. This triggers a Python cgi-bin script that performs some tasks which may take around ten seconds to finish. Upon completion of the task, the Python script instruc ...

Incorporating HTML snippets into files using PHP

When attempting to insert an HTML line into the "userlist.php" file using PHP code, I encountered an issue: <?php $username = "pajlok"; $type = ".jpg"; $html = <<<EOD <div onclick="window.location.href = 'user/pajlok/'" styl ...

What methods can be used to identify statistics on active applications, such as the foreground app, on the most recent version of

Is it possible for the latest version of Android to give developers the ability to detect which application is currently open in the foreground or provide a list of all opened apps, even if they are not running in the foreground? I can have access to all p ...

Methods to prevent ExtentReports from transforming HTML references in your Selenium logs into real HTML code

Having an issue with ExtentReports 4 for .Net and HTML V3 reporter. Whenever a test fails, the failure message is displayed in the report. However, if the failure message contains an HTML tag, it gets converted to actual HTML on the report, causing layout ...

What is the best way to display HTML and JavaScript content using Express?

Currently, I am working on a simple express app which comprises of two routes. One route is responsible for rendering html, while the other route is supposed to render a JavaScript file. To keep things organized, I plan to store the html files in a ./views ...

Attempting to fill a collection of JSON entities through a GET call?

When handling a GET request that contains a list of JSON objects, I want to display the data in an input field on the screen using ng-model for data binding. The structure of the JSON get request is as follows: [{"make":"Mahindra","vin":"1987","model":"XU ...

Change the value of an input button in an HTML tag without assigning any value to it

Currently, I am utilizing the UserWP plugin on my WordPress registration page. The button on the form currently reads "Submit Query," which I find to be subpar. I would much prefer it to say "Register" instead. Unfortunately, there doesn't seem to be ...

Are you utilizing ListViews in your Android application?

Recently delving into the realm of Android SDK, I find myself facing a query. My objective is to configure a ListView featuring a colored rectangle on the left side of each row with accompanying text. Further, I aim to enable the functionality where clic ...

Styling the scroll bar within a fixed parent container's inner div with CSS

Check out the JSBIN link here: JSBIN The modules container has a fixed height of 100%. I am attempting to make the list items scroll while keeping the search div fixed within the wrapper container, ensuring that the search bar remains visible at all times ...