Wednesday, February 27, 2013

The Curious Case of Missing 'px' in Javascript for Chrome/Safari/Firefox

When one uses the transitional DOCTYPE in Chrome/Safari/Firefox, your Javascript assignment of value to marginTop or top will not be successful if you left out the 'px'. For example, if you want to move a dummy DIV to a height of 100 pixel from the top, you might do this: document.getElementById('dummy').style.top = 100; It will work if you are not using the transitional DOCTYPE. If you are using the transitional DOCTYPE, you need to assign it with a 'px' at the end: <!DOCTYPE...
Read More »

Friday, February 1, 2013

Javascript to Change Div & Body Style in IFrame

Before showing the codes, here are the conditions that these codes WON'T work: Run with Chrome in localhost environment Cross domain for the main HTML and dummy.html in your iframe. These codes have to comply with the same domain policy or hackers will be very happy if it is not The Main HTML: <iframe id="myFrame" scrolling="no" style="overflow: hidden; height: 580px; width: 325px;" src="dummy.html"></iframe> <script> function changeColor() {     document.getElementById('myFrame').contentWindow.document.getElementById('divInDummy').style.backgroundColor...
Read More »