Looking to optimize my code, I am only interested in targeting devices that have a slower page loading time, perhaps those taking more than 12 seconds to fully load.
Looking to optimize my code, I am only interested in targeting devices that have a slower page loading time, perhaps those taking more than 12 seconds to fully load.
document.readyState
is a useful property that returns "complete"
once the page has finished loading. To ensure that your page doesn't stay hanging, you can set a timeout and redirect to another URL if the value of readyState
is not "complete"
after 12 seconds.
setTimeout(function () {
// The document may not be fully loaded yet.
if (document.readyState !== 'complete') {
top.location.href = 'http://myweb.com/super-minimal-page.html';
}
}, 12000);
Create a Boolean
variable at the beginning of your script and initialize it with a value of false. Then, set up a setTimeout
function for 12 seconds that will call a specific function in case the page is not loaded.
Inside the document.load function, change the Boolean variable to true and then check for its value in your pageNotLoaded function as shown below:
<script type="text/javascript>
var pageIsLoaded = false;
setTimeout(PageNotLoaded, 12000);
$(function(){
pageIsLoaded = true;
});
function PageNotLoaded()
{
if(!pageIsLoaded)
{
// Insert your code here
}
}
</script>
I am currently working on an application that relies on SignalR for communication with a desktop application. In order to make use of SignalR, I include jQuery in my .ts file. However, after migrating from Angular 7 to Angular 8, it appears that this setup ...
I'm currently testing out the bootstrap 3 navbar feature on my meteor application, but I'm encountering some issues specifically on mobile devices. The problem seems to be that the toggle button is not showing up as expected. Interestingly, it wo ...
I've been writing a test using Selenium WebDriverJS, and now I need to simulate pressing a key on the keyboard. Is it possible to do this with Selenium WebDriverJS? If so, how can it be done? In Java, we achieve this as follows: driver.findElement(Lo ...
Is there a way to calculate the number of <option> elements in a <select> element using jQuery? <select data-attr="dropdown" id="input1"> <option value="Male" id="Male">Male</option> <option value="Female" id="Female"& ...
What is the best way to use a changing parameter name when accessing a variable? For instance: opener.document.form.namerow_3.value = this.cells[0].innerHTML; opener.window.form.{varaible}.value=this.cells[0].innerHTML; In this scenario, the parameter ...
Currently, I am facing a challenge. I have multiple forms on a single page that are being submitted to the backend asynchronously via ajax. Some of these forms require a file upload without interrupting the process, so it needs to be handled asynchronousl ...
Using both JavaScript and JQuery. Let's imagine there is an array called ListArray with various sentences inside. Sounds easy enough. Is there a way to achieve this? var List = for (var i = 0; i < 10; i++) { //iterate over an array here to c ...
Recently, I created a form using Bootstrap 4. The validation process is done through a PHP file with an AJAX call and it's functioning correctly, except for one issue. I want the input class to switch from "invalid" to "valid" as soon as the user begi ...
I've been experimenting with different methods to tackle this issue. Essentially, I need to update the content of multiple dropdowns in the same way. I wanted to use an each or a while loop to keep the code DRY, but my experience in coffeeScript is li ...
controller.js angular.module('app.main') .controller('MainCtrl', function ($scope, currentUser, addAPI) { $scope.form = {}; $scope.subdomain = currentUser.domainName; $scope.add = function () { addAPI.addAdmin(loc ...
Child component <template> <div> <h3>Child Component</h3> <div> <button @click="changeValue()">Update Parent Value</button> </div> </div> </template> <script> export ...
Here is my code snippet where I am attempting to retrieve values of multiple selected checkboxes, but it seems to be malfunctioning. Can you please guide me on what mistake I might be making? Just to clarify, the list is dynamic and will not be limited to ...
Is there a way to use ngFileUpload to read the contents of a csv file before saving it to a database? $scope.checkAndUploadFile = function (file) { $scope.uploadFileProgress = true; Upload.upload({ method: 'POST', url: & ...
I am facing an issue while trying to run a legacy create-react-app that utilizes Sass. Initially, when I ran npm start, I encountered the error 'Cannot find module sass', which resembled the message found in this stack overflow post. To resolve t ...
Have you ever wondered how websites like Facebook manage to float certain elements, such as a menu bar or social plugin, when the user scrolls past a specific point? This functionality can be achieved through JavaScript (jQuery) events that trigger when a ...
Currently, I'm attempting to implement an onclick() event in pdfjs. After attempting to add a method within the pdf.js file to handle the onclick functionality, I encountered an error upon clicking "Uncaught ReferenceError: displayAttachmentsOnLocati ...
Whenever I fill out the form in the footer and hit submit, it directs me to a different page while automatically scrolling back down to the footer. I'm looking for a solution that prevents this automatic scrolling. I've attempted using window.sc ...
I am attempting to link a model (a boolean value) to a checkbox created with Foundation (Zurb). I have created a small demonstration displaying the issue: http://jsfiddle.net/JmZes/53/ One approach could involve simply creating a function that triggers o ...
Is it possible to prevent an HTML form submit button from being greyed out when disabled? Issue at hand: I am looking to disable the entire form, but find that having the submit button grey out before the rest of the form does not look visually appealing. ...
Currently, I am designing a website with two sidebars and a center wrapper for the main content. The sidebars will contain links that jump the user to different sections of the page. I have fixed the position of the sidebars so they stay visible as the use ...