Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT


  Get hostname from a URL using JavaScript

Sometimes we may have strings which contain some UR;s and we may want to retrieve the hostname from the URLs for some statistic use. For example, we may have a URL : We may want to retrieve the from the URL. How? Use regular expression. Here I give an example using JavaScript. If you want to check whether a string is a URL or not. Refer to Detect URLs in a Block of Text. In JavaScript, we can have a regular expression like var pattern=/(.+:\/\...

   JavaScript,URL,regular expression, Hostname     2012-06-15 09:16:45

  Java code to retrieve Bing background image path

When Microsoft presented their search engine Bing, this new design gave us some surprise, especially its background images, they are very beautiful and it will change every day. But   unfortunately we cannot save the image onto our PC by right clicking the mouse.  After some research on its source code, I found a feasible but not so sophisticated way to achieve this, we can retrieve the image path from the source code and then use this path we can download the image. This is just to sh...

   Java,Bing,Background image path,URL,Download,Save     2012-05-02 10:51:51

  An alternative way to parse URL in JavaScript

Normally when we need to process URL in JavaScript, we may use the location object. Then we can use location.hostname,location.href,location.port etc to get the information we need. In this post, we will parse an URL with an alternative way. We can use an URL to create a DOM object by calling document.createElement("a"). The complete code is: function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':',''), host: a.ho...

   URL,location,parse     2014-03-03 07:05:11

  About short URL and its implementation

IntroductionURL shortening is a kind of technique to convert a long URL to a short URL. There are many companies now providing this kind of service, we now take Google's URL shortener service as an example.First we navigate to, then we enter a random URL into the text field, here we use as the input, it will return us an shortened URL : URL ParsingWhen we type in browser address bar, the DNS...

       2012-07-02 07:15:09

  Crash your Chrome with %%30%30

Have you ever wondered a simple string can crash one of the most sophisticated designed web browsers -- Chrome? There is a finding from Andris Atteka who found that a null string "%%30%30" appended to an URL can crash Chrome. For example, if you have below URL in your browser address bar or you mouse over below URL, Chrome will crash: When the browser crashed, it may show : Or on Windows, you will see : This bug has been reported to Google at Is...

   CRASH,SECURITY,CHROME,GOOGLE     2015-09-20 08:24:16

  Source code for sharing webpage to facebook

Copy and paste the following code blocks into your site and replace '<url>' with the link you want to Share.Text link:<script>function fbs_click() {u=location.href;t=document.title;''+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><a rel="nofollow" href="<;url>" onclick="return fbs_click()" target="_blank...

   Source code,Facebook,Share,Webpage     2011-07-23 06:52:07

  Use of @font-face

Almost all web browsers(including the dinosaur browser IE6) support the web font property @font-face. Its usage is: @font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('webfont.woff') format('woff'), /* Modern Browsers */ url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */ url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */ } Now we...

   CSS,@font-face     2014-06-08 07:17:34

  Social media sharing codes

Social media is becoming a very important traffic source to one website. We can see social media share buttons or links in most websites ranging from news website to personal blogs. It is also a very important optimization area where many SEO experts recommend. There are many social medias we can share our links to such as Facebook and Twitter. Most of these website provide share button for us to easily integrate them into our websites, but these buttons usually have default styles(fixed size, f...

   Social media,Share button,Cutomize     2013-07-18 23:12:45

  How to let Google index AJAX contents?

There are lots of websites containing only one page now with the popularity of AJAX. The website will load different contents according to different inputs from users. This approach provides good user experience and it also helps save bandwidth, the drawback is that AJAX contents are not easy to be indexed by search engines. For example, if you have a website: Users can see different contents with the appended # structure in the URL: h...

   AJAX,Search engine,Google,History     2013-07-16 00:47:14

  A Hello, World Servlet

Servlets are the pure Java solution to handle web requests. Many application will use servlets instead of JSP and others will use servlets in conjunction with JSP. Experienced JSP programmers use servlets in conjunction with JSP to create clearer and simpler applications. The servlets handle Java processing: form handing, calculation and database queries. JSP formats the results. Servlets belong in WEB-INF/classes. On this machine, the source is in Java source in /var/www/hosts/

   Web.xml,Tomcat,Servlet,WEB-INF     2011-05-08 10:31:39