Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  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.hostname, port: a.port, query: a.search, params: (function(){ var ret = {}, seg = a.search.replace(/^\?...

11,306 1       URL LOCATION PARSE


  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 : http://www.example.com/aboutus.html. We may want to retrieve the www.example.com 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=/(.+:\/\/)?([^\/]+)(\/.*)*/i;the regular expression pattern can be used to get the hostname. There are three...

18,446 0       JAVASCRIPT REGULAR EXPRESSION URL HOSTNAME


  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 show you how we can save the background image, please do not use it on commercial products since these...

8,102 0       JAVA DOWNLOAD URL BING BACKGROUND IMAGE PATH SAVE