Monday, December 31, 2012

Add a Background Music (MP3) to your Blogger

Here's the simplest method (HTML/JavaScript Widget/Gadget) I can find: <object type="application/x-shockwave-flash" data="https://sites.google.com/site/blogknol/blogknol/dewplayer-multi.swf" width="240" height="20" id="dewplayer" name="dewplayer"> <param name="wmode" value="transparent" /><param name="movie" value="https://sites.google.com/site/blogknol/blogknol/dewplayer-multi.swf"...
Read More »

Sunday, December 30, 2012

Javascript Mouse Wheel Event Handler

I found several examples online but none of it works 100% as expected. I sort of modified them and came out with the version which works 100% for me on Chrome, IE, Safari and Firefox. Here it is: var ff = (navigator.userAgent.indexOf("Firefox") != -1); if (ff) {   mousewheelevent = "DOMMouseScroll"; } else {   mousewheelevent = "mousewheel"; } if (document.attachEvent) {   document.attachEvent("on"+mousewheelevent, catchWheel); } else if (document.addEventListener)...
Read More »

The Death of Web Page ...............???

Ever since the social network pages such as Facebook, Twitter and Linked'in came into picture, the demand of conventional web pages are slowing down. Especially blogs, you'll see less and less new blogs or many blogs are switching over to Facebook pages. Additionally, with the mobile apps getting more and more popular, web pages take another hit. Web users nowadays prefer Facebook and mobile...
Read More »

Is It The End of Javascript?

Since almost all of our javascript codes can be replaced by jQuery equivalent, do we still need Javascript? The answer is yes and no. Yes, if you want to place dynamic HTML content in a controlled page such as Ebay. Ebay doesn't allow the call to an external javascript such as the jQuery library. You have no choice but to switch back to conventional javascript for actions. For me, I would encourage...
Read More »

Tuesday, December 25, 2012

Pre-fill Text Input Box with Grey Text using Javascript

I don't know since when the pre-filled grey text in the text input box becomes so popular. Here's what I do. I hope these are the simplest codes. Enjoy! The Javascript & HTML: <script> function checkText(action) {   if (document.getElementById('myTextID').value == 'Default Text' && action == 'focus') {     document.getElementById('myTextID').value = "";   }   else if (document.getElementById('myTextID').value ==...
Read More »

Friday, December 21, 2012

Render Text in PNG Format using PHP GD2 in IIS Environment

The following example won't work if you are running GD version 1 in your PHP server. Some modications are required to make it work. GD's imagettftext by default cannot set the spacing between characters. If you want to force spacing between characters, you can display each character at a time calculating the spacing your self using a loop. However, there is one problem setting the spacing: each...
Read More »

Sunday, December 16, 2012

Check Out Facebook Friends with Specific Birthday Month FQL

As in my previous post, here's the modified version to list out friends with birthday in the month of May in Facebook. SELECT name,uid,birthday_date FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2=me()) AND strpos(birthday_date,'05') = 0 You can change the month (highlighted in blue) to some other value...
Read More »

Saturday, December 15, 2012

Check Out Facebook Friends with Most Mutual Friend FQL

As in my previous post, here's the modified version to list out friends with most mutual friends in Facebook. SELECT name,uid,mutual_friend_count FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2=me()) ORDER BY mutual_friend_count DESC ...
Read More »

Check Out The Seniors Among your Facebook Friends Using FQL

As we know that we are all assigned an ID as we signed up a Facebook account. The account grows bigger as time goes by. We can tell from this little hint who signed up the FB account earlier by comparing the user ID. Here's the FQL used to generate the list according to the time first joined the social network: SELECT name,uid FROM user WHERE uid in (SELECT uid1 FROM friend WHERE uid2=me() ORDER BY uid1 ASC) As in the earlier post, you can try out this FQL query here: ...
Read More »

Friday, December 14, 2012

Check Out Facebook Friends with Most Friend FQL

Here's a fun FQL to find out who among your FB friends has the most friends: SELECT name,friend_count,mutual_friend_count FROM user WHERE uid in (SELECT uid1 FROM friend WHERE uid2=me()) ORDER BY friend_count DESC Just copy and paste from the above query codes and paste it to: https://developers.facebook.com/tools/explorer I also added the mutual_friend_count for more fun. You...
Read More »

Sunday, December 9, 2012

jQuery: Dim an Entity and Hide it

Make sure you call the jQuery library before running any jQuery functions. Either library version is fine, Google or jQuery Foundation. The following shows the code to dim the myDiv to 0.1 opacity within 500ms. After that, hide the DIV: $('#myDiv').fadeTo(500, 0.1, function() {   $('#myDiv').css({visibility: "hidden"}); }); If you straight away animate the opacity to 0 without hiding the DIV, the DIV will stay there although it is not visible nor it is hidden. If the...
Read More »

Sunday, August 26, 2012

jQuery toggle() not working?

I just found out that toggle() is not working with the JQuery version I've been using. I am using 1.72 from this link. After switching to version 1.80, I now can lay back a bit by enjoying the convenience of toggle() function which requires many lines of codes if using javascript to control the visibility of an element. Silly me. ;...
Read More »

Tuesday, August 21, 2012

Simple HTML/Javascript Codes to Display your Live Mouse Coordinates (Firefox Fix)

The firefox friendly version: <html> <head> <script type="text/javascript"> var ff = (navigator.userAgent.indexOf("Firefox") != -1); function showXY(e) {   if (ff) {      var s = 'X=' + e.pageX + ' Y=' + e.pageY;      document.getElementById('coordinates').textContent = s;   }   else {      var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY;     ...
Read More »

Monday, August 20, 2012

Simple HTML/Javascript Codes to Display your Live Mouse Coordinates

Here they are: <html> <head> <script type="text/javascript"> function showXY() {    var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY;    document.getElementById('coordinates').innerText = s; } </script></head> <body onmousemove=showXY()> <div id="coordinates"></div> </body> </html> The key component for this to work is highlighted in green. However this won't work in Firefox....
Read More »

Weird Chrome Javascript Problem

I encounter this today that the Javascript var top cannot be used in Chrome. Weird. It works well in Safari and IE. In Chrome, the variable name is stored as [Object Window]. Solution: Just rename top variable to something else...
Read More »

PHP to Replace Last Character in a String

Seems like a trivial code but it's nice to put it here as I tend to forgot the syntax from time to time: $line = preg_replace("/\n$/","",$line); // To replace last newline character $line = preg_replace("/\r\n$/","",$line); // To replace last newline character in Windows environment $line = preg_replace("/\s$/","",$line); // To replace last space in a string Assuming your string is stored in $line...
Read More »

Sunday, August 5, 2012

Protect Your CSS and Javascript Codes

Update 20th of March 2013: Here's a updated version to include a simple minification before sending your Javascript / CSS codes to the browser especially Chrome: http://webtrick101.blogspot.com/2013/03/protect-your-external-css-and.html Actually there is no 100% way to protect your CSS and Javascript codes as if the person who intended to copy is using Google Chrome browser, your codes will be...
Read More »

Saturday, August 4, 2012

Setting Permission for PHP/IIS Environment Especially When PHP Temporary File Facility Is Used

When PHP is run on IIS platform, users will run into the following problems: (A) Files are not able to be written, created, or rewritten on the C:\inetpub\wwwroot\ directory. (B) PHP uploaded temporary file will not be able to be written and this results in file upload problem. For example, $_FILES["FileID"]["tmp_name"] will not be able to be written. (C) PHP tmpfile() command will fail. In order...
Read More »

Sunday, July 15, 2012

Save Your PHP in UTF-8 Format Without BOM

BOM or byte order mark is to indicate the byte order of your file. If your PHP file contains non-English characters, UTF-8 formatted PHP file will display as question mark(?) if the PHP script is run on Linux/Apache web service platform. However, no problem is found on Windows/IIS web servers. You can run the following PHP codes to check whether your PHP got BOM: <?php $handle = fopen('yourfilename.php','r'); ...
Read More »

Adding PHPExcel PEAR Library in Shared Hosting Environment

You need to have the PEAR library installed in your shared host/server before this. If you haven't done so, you can check out my earlier post on how to do this. The Steps I used: You can download the PHPExcel here. Choose the PEAR version. As of now, the current version is 1.77 and the file size for the .tgz file is 11.7MB. Extract the .tgz file. You'll see a PHPExcel.php and a PHPExcel folder. Like other PEAR add-ons, you just need to copy the PHP file and the folder to your PEAR...
Read More »

Install PEAR for Shared Hosting

PEAR is undeniably a good source of PHP code library that will make programmers' life a lot easier. Installing PEAR on Windows/IIS platform is easy especially when you have admin access to your PC/server. When it comes installing PEAR in a shared hosting environment, admin access is null and there are workarounds that need to be addressed in order to use the PEAR library in the restricted platform. Here are the steps I use: Go to http://pear.php.net/go-pearCopy the content and save...
Read More »

Tuesday, February 7, 2012

Image (<IMG>) SRC Dynamic Update Using Script Not Working in IE

If you have HTML code running this dynamically changing image:<script>document.getElementById('myID').src="myscript";</script>HTML:<img src="myscript" id=myID>This won't work in IE. You need this:<script>var randomNo=Math.floor(Math.random()*10000);document.getElementById('myID').src="myscript?"+randomNo;</script>As IE will refer to cache data if it sees the data is the same as the next click.You can also change to other methods of generating random numbers....
Read More »

Tuesday, January 3, 2012

Chrome/Firefox/Safari Not Able to Read External Javascript/CSS

This is something a web programmer needs to take note as this could lengthen your coding time if this is not taken into account.Chrome/Firefox/Safari is not able to read external Javascript/CSS with commands such as:<link rel="stylesheet" type="text/css" href="testcss.php" /><script language="JavaScript" src="testjs.php"></script>if your broswer runs in STANDARD mode (with the declaration of DOCTYPE).Fix:1) Include your CSS/JAVASCRIPT in your HTML file that you are running,...
Read More »

iFrame Transparency Problem in IE and Solution

With the default setting, IE sets the background color of a HTML body to white if no value is set.For other browsers, the background color is set to transparent by default.In order to make IE iframe HTML to accept transparency, one has to set both the iFrame and HTML body value correctly.The iFrame:<iframe src="dummy.html" width=400 height=400 allowtransparency="true">Inside dummy.html:<body style="background-color:transparent">Well, that's the fix for IE. Just two small steps.Yes,...
Read More »

Monday, January 2, 2012

Chrome and setTimeout() Javascript Function

I once made the O capital letter and it won't work in Chrome.setTimeout() - OKsetTimeOut() - Not working in ChromeJust a trivial post but it is interesti...
Read More »