Skip to content

Tag: javascript

Remove empty tags using RegEx

I want to delete empty tags such as <label></label>, <font> </font> so that: will be cleaned as: I have this RegEx in javascript, but it deletes the the empty tags but it also delete this: “<i>italic</i></p>” What I am missing? Answer You have “not s…

Disable same origin policy in Chrome

Is there any way to disable the Same-origin policy on Google’s Chrome browser? Answer Close chrome (or chromium) and restart with the –disable-web-security argument. I just tested this and verified that I can access the contents of an iframe with src=”http://google.com” embedded in a p…

Get the Size of a CSS Background Image Using JavaScript?

Is it possible to use JavaScript to get the actual size (width and height in pixels) of a CSS referenced background image? Answer Yes, and I’d do it like this… Some notes… We need to remove the url() part that JavaScript returns to get the proper image source. We need to split on , in case t…

Calling a method from an event handler

I have this code I am working on but every time I call init method I keep getting an error: this.addElement is not a function Is it because I can’t call methods from event handlers? Answer You should read this book, JavaScript: the Good Parts and visit the Crockenator’s web site here, crockford.co…

I am trying to make a simple toggle button in javascript

I am trying to make a simple toggle button in javascript. However, the button will only turn “OFF” and will not turn back “ON” I am running:HP Netbook : Ubuntu Linux 10.04 : Firefox for Ubuntu 1.0. Answer Both of your if statements are getting executed one after each other, as you chan…