Modifying the DOM in Safari before unloading a webpage

I need a way to display a loading animation when I navigate between pages on my website. To achieve this, I have added the following HTML code for the loader:

<div class="ajax-loader"><i class="icon-spin5"></i></div>

And here is the CSS code for styling the loader:

.ajax-loader {
    z-index: 1;
    position: fixed;
    top: 50vh;
    left: 50vw;
    transform: translate(-50%, -50%);
    color: white;
    opacity: 0;
    pointer-events: none;
    transition: all ease-in-out .25s;

    i {
        display: inline-block;
        font-size: 80px;
        width: 80px;
        height: 80px;
        animation: spin 3s linear infinite;

        @media @step1, @step2 {
            font-size: 2em;
        }
    }

    &.active {
        opacity: 1;
    }
}

In addition, here is the JavaScript code that controls the loader:

$(document).ready(function() {
    // Show loader when changing pages
    window.onbeforeunload = function(e) {
        // Display ajax loader
        $('.ajax-loader').addClass('active');
    };
});

Everything works as expected in Internet Explorer, Firefox, and Chrome, but not in Safari (on Mac and iOS).

Does anyone have any suggestions or ideas to address this issue? Thank you!

Answer №1

It is possible that you forgot to include the -webkit-transition and -webkit-transform properties in your CSS

Answer №2

It is likely that using document.pagehide will be effective in Safari.

document.pagehide = function(e) {
    $('.ajax-loader').addClass('active');
};

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

Listen for changes in the clientWidth of an element in Vue 3

Hey there, I'm currently working on a project where I need to track the clientWidth of a component when it gets resized. I'm trying to achieve this by using: const myEl = document.querySelector('#myID') and monitoring changes in myEl. ...

Determining the dimensions of a div with a scrollbar using Jquery

Is there a way to get the width and height of a div with scroll that includes both visible and hidden content using JQuery? If anyone has a solution for getting these values, please share. <div id="area" class="divLeftCem area"> <div id="pan ...

Duplicating a file within the Flask app directory while understanding its designated web route

After creating a web path of a file, I utilized the following code snippet: URL.createObjectURL(event.target.files[0]); Following an ajax call, I sent this link to Python (Flask). I am now interested in learning how to utilize this link to duplicate the ...

How can I isolate the CSS of my Vue application from the rest of the website?

I am currently working on developing a unique "plugin" that will feature a user interface to be integrated into various vendor websites. This particular plugin is designed to be CMS agnostic, and due to SEO concerns, I am unable to utilize an iframe. My go ...

Adjust the border color when hovering over a Material UI TextField

Trying to modify the hover color of Material UI's outlined TextFeild has been a challenge. It appears to have multiple states such as active, focus, focused:hover, etc. Came across this post that tackles my issue, but I prefer not to include MuiTheme ...

A guide on incorporating a customized Google map into your website

Recently, I utilized the Google Map editing service from this site: https://developers.google.com/maps/documentation/javascript/styling This link provided me with two things: 1. A JSON code 2. The Google API link However, I am unsure about how to incorpo ...

Can you please provide me with the steps on how to show only non-zero values in MySQL using PHP and

This image shows data entry into a MySQL database. The image above displays the output I am currently receiving, However, I want to show only non-zero fields as output, which means from the "Sample Received" column to the "Library QC" column only. The P ...

Avoiding content resizing when using a drawer in Material UI

My project features a drawer that expands, but I am encountering an issue where the content inside the drawer resizes when expanded. However, this is not the desired outcome. I want the expanded drawer to overlay the content without resizing it. How can I ...

Having trouble loading the Google API using getScript. Is displaying a ReferenceError message: "Variable google not found."

I am attempting to dynamically load the Google API using the getScript() method for implementing a "Place Autocomplete Address Form". For more information, you can visit this link: https://developers.google.com/maps/documentation/javascript/examples/places ...

Error encountered while using JQuery Ajax to invoke server-side method in ASP C#

How can I call a server-side method using AJAX in an ASP C# application? I have the below code in my aspx file: function editApp(appID) { $.ajax({ type: "POST", url: "Default.aspx/GetSquare", contentTy ...

employing document.write() specifically for a designated division

This is the coding: $(document).ready(function(){ var Jstr = { "JSON" : [ { "Eid" : 102,"Ename":"", "Ecode" : "<input type ='text'/>", "Eprops": {"name": "", "value":"", "maxlength":""}} ] } ; $(".search").click(funct ...

The parent div has margin and is set to auto, but the child does not fill the entire width at 100%

My goal is to design a menu that spans the entire width of the page with some margin on the left and right sides. Here is the layout: <div class="parent"> <div class="content"> <div class="element"> <a><p ...

The Jquery function is failing to activate when selecting an option

I am encountering an issue with triggering a jQuery function when selecting a value from a dropdown. The change event is not being fired, while the click event works but triggers twice. I specifically need only the change event to be triggered. <scri ...

Exclude the UL hierarchy from removing a class in jQuery

Check out this fiddle to see the code snippet: http://jsfiddle.net/3mpire/yTzGA/1/ I am using jQuery and I need to figure out how to remove the "active" class from all LIs except for the one that is deepest within the hierarchy. <div class="navpole"&g ...

Obtain the Zero-width non-joiner character (‌) using the innerHTML attribute

I am attempting to retrieve a &zwnj; using the innerHTML method The desired output should be This section contains a zero-width‌&zwnj;non-joiner, a non-breaking&nbsp;space &amp; an ampersand However, the current output is: This part c ...

invoking the controller through the view with ajax

Having trouble calling a controller and passing the data stored in the variable mat. My attempt to call the controller function is not working. Any guidance on how to proceed with this issue? $('#buttonadd').click(function () { var mat = $(& ...

To open a popup menu with a text box, simply click on the text box

Whenever the text box text is clicked, a popup menu should open with a text box. Similarly, when the filter icon in the right side corner is clicked, a menu should open with a list of checkboxes. However, currently both menus are opening when clicking on b ...

Having trouble making the jQuery post method work to invoke a function in a Coldfusion component

While attempting to invoke a cfc method through ajax using jQuery's post() method, I repeatedly encounter an error message stating that "the xxx parameter to the yyy function is required but was not passed in". Below is the cfc function in question: ...

What is the Best Way to Perform Multiple Ajax Requests in a Class Using Jquery?

I am experiencing an issue with the following code. When I hard code the link, it runs correctly. However, when I try to pass multiple shortened URLs into the ajax call using the $.each() function, the code breaks. Each short URL is alerted individually, ...

Wrapping text in Bootstrap 4 containers for better readability

I am attempting to wrap the title text around a span object. So far, I have been successful in getting everything aligned correctly, but the final step of wrapping the text seems challenging. My suspicion is that the issue lies in the separation of contain ...