Category Archives: HTML

PHP – Prevent GIF image loaded from browser cache

I would like to show a GIF image on a website but i found that the animation is not working as the browser caches the GIF image after first load. Here is a PHP workaround by adding the current timestamp to the image src url.

<img src="https://eureka.ykyuen.info/example.gif?v=<?php echo Date("Y.m.d.G.i.s"); ?>" />

 

Done =)

Reference: cache woes, how to force an image to refresh or load fresh

Advertisements

jQuery & Javascript – Capture the Browser or Tab Closed Event

I was working on a WordPress project which i need to clear the PHP session when the browser or browser tab is closed. Although Javascript provides the window.onbeforeunload event but it will be triggered even whenever you leave the website. Finally i got a simple solution from Daniel Melo in StackOverflow. The following code required jQuery and i have included the Google one in the HTML.

In your web root, create the js/check_browser_close.js. Continue reading jQuery & Javascript – Capture the Browser or Tab Closed Event

HTML – Remove Dotted Line of Transparent Button

Not only the HTML link will have a dotted outline after being clicked, if you have a transparent input button, you will find the dotted outline too.

 

The following css could help you to remove it.

/*for FireFox*/
input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner {   
  border : 0px;
} 
/*for IE8 */
input[type="submit"]:focus, input[type="button"]:focus {     
  outline : none; 
}

Continue reading HTML – Remove Dotted Line of Transparent Button

PHP – Convert Special Characters to HTML Entities

I was working on a legacy CMS which has a HTML form with ISO-8859-1 encoding. I found that whenever i got an Apostrophe (‘) in the string, the data cannot be persisted.

I guess it should be some encoding problem which makes the database fail to persist the data. So i try to use the PHP str_replace function to replace those Apostrophe but it has never replaced them successfully.

Finally, i got the solution. PHP provide a function called htmlspecialchars which will substitute the following special characters into HTML entities. Continue reading PHP – Convert Special Characters to HTML Entities