Javascript setTimeout will not work in my script [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 21 hours ago.
Improve this question
I want to set a delayed event, using setTimeout. No big thing, except it isn't working and it has been taking me hours to figure out why.
So, I went to W3Schools to check and found this example:
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_settimeout1
Working fine there, so I copied the logic to my own HTML file on my machine. No way, it doesn't work.
I do not understand how such a simple thing can behave differently on the same machine, browser and version simply because one is sitting at W3Schools and the other at my plain HTML script.
This is the script I copied:
<script>
let timeout;
function myFunction() {
timeout = setTimeout(alertFunc, 3000);
}
function alertFunc() {
alert("Hello!");
}
myFunction();
</script>
Doesn't work when copied to my machine.

Related

alert called by onload event not running? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm creating a chrome extension, but I'm struggling with the Onload event. I'm not sure what's wrong with my code. It works when I run it from this code snippet, but not in my text editor. I've tried disabling Jslint but it still won't show the alert. The problem could be in running the function, calling the alert, or calling the onLoad event, but I'm not sure. I'm testing it using a chrome-based preview tool in the brackets text editor. Any idea what's going on and why?
function showAlert() {
alert ("you are an idiot");
}
<script src="justanotherfile.js"></script>
<body onload="showAlert()"></body>
Did you include this in the manifest file?
"scripts": [
"justanotherfile.js"
]

My script works the first time and does anymore not after reload on this online IDE [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a slight problem with this online code editor. When I launch my snippet, it only works one time. If I try to bring any modification to the code, it crashes for unknown reasons.
https://playcode.io/313059?tabs=console&script.js&output
Any clue of what is going on here?
I just checked and I think that your code is executing while the editor is not loaded yet. Wait for the document or window to be loaded and then execute the code as following:
$( document ).ready(function() {
var block = document.getElementById('block');
var block_scale = window
.getComputedStyle(block, null)
.getPropertyValue("transform");
var matrix = block_scale.match(/\d+(?:\.\d+)?/gm);
console.log(matrix[0]);
});

Cannot Remove Attribute Javascript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
If I try the code below on the console in Chrome, it is working. But the code is not working in my Javascript extension in Chrome.
var region = document.getElementById("physicalDeliveryOfficeName");
region.removeAttribute("onchange");
Any thoughts what am I doing wrong? Tried to add this line in my function and on the top of my script but it is not working.
This is due to the execution environment that it is isolated in a Chrome extension.
You have to inject the code into the page to do modify the page context handlers.
Please see Insert code into the page context using a content script
It works in console because the dom has loaded. Wrap your code in an event handler.
document.addEventListener("DOMContentLoaded", function(event) {
var region = document.getElementById("physicalDeliveryOfficeName");
region.removeAttribute("onchange");
});
https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded

Jquery .click() causes code to break [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Adding this line of code $("#locate-me-button").click(loadLocation()); breaks my entire JavaScript code file even if I don't click the #locate-me-button element. When this line is commented out the entire file works perfectly again. Why would that be?
You are invoking the function as passing its return value to event handler, just pass the function reference to .click()
$("#locate-me-button").click(loadLocation);
//^ () is removed
The another way (at least for case that you have parameter):
$("#locate-me-button").click(function(){
loadLocation();
});

Wordpress issues with loading the website on Firefox [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
as mentioned in the Title, when I load my Website on Firefox there seem to be rendering problems. Although when I load it on Chrome or Safari it looks and renders as it should.
I will post some screenshots to make the issue even clearer.
Many thanks in advance for your help.
Website view on Firefox
Website view on Chrome
Error on below line, correct it.
src: url(‘library/fonts/destroy_-webfont.eot');
Correction:
src: url('library/fonts/destroy_-webfont.eot');
Seems as if you are missing some css. Check to see if the css files are being loaded properly in the developer console. If they are being loaded correctly, then you may need to add some mozilla specific styles.
Are there any other errors in the browser console that would prevent execution of the css?
Welcome to the world of cross browser compatibility issues.

Categories

Resources