Skip to content
Advertisement

How to create a tag with Javascript?

I’m looking for a way to insert a <style> tag into an HTML page with JavaScript. The best way I found so far: This works in Firefox, Opera and Internet Explorer but not in Google Chrome. Also it’s a bit ugly with the <br> in front for IE. Does anyone know of a way to create a <style> tag that

Cross-browser way to determine whether a DOM event was cancelled

Is there a cross-browser way from a Javascript event handler to determine whether the event has been cancelled by a previous handler? IE and other browsers like Chrome etc. have an event.returnValue property that can be tested, but FireFox doesn’t appear to have any such property. Here’s an example of the scenario I’m talking about. You have a form like

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? Answer TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking

Compare two dates with JavaScript

Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes. Answer The Date object will do what you want – construct one for each date, then compare them using the >, <, <= or >=. The ==, !=, ===,

How to check if element is visible after scrolling?

I’m loading elements via AJAX. Some of them are only visible if you scroll down the page. Is there any way I can know if an element is now in the visible part of the page? Answer This should do the trick: Simple Utility Function This will allow you to call a utility function that accepts the element you’re looking

Possible to flash a Browser window using Javascript?

Like many programs flash their window on the taskbar / dock to alert the user to switch to the program, Is it possible to flash the Browser window using Javascript? (FireFox-only scripts are also welcome) This is useful for web-based Chat / Forum / Community-based software where there is lots of real-time activity. Answer @Hexagon Theory: Why would you ever

Advertisement