JQuery’s $(document).ready() method

Web programming
JQuery has a method that can help you when developing a website called "document.ready", in JQuery language: "$(document).ready()". This method let's you start doing things in your page using javascript once the document is ready but without having to wait for all the images to load. I mean, if you don't use JQuery and you want to do something like an effect or whatever when the page loads, you will for sure use the window.onload to start it, but if you have used this option in the past you will notice that window.onload needs the entirely page to be loaded, and sometimes due to images or something that is being requested to another server this takes some time making the effect less impressive or even regrettable. So JQuery gives you…
Read More

Third-party cookies

Web security
I am sure you have read something about third party cookies before, mainly because if you check your browser options you have an option to block those type of cookies. But first of all, let's start from the beginning: What is a Cookie? A cookie is something to eat made with some flour and water and.... wait, that's not what I was talking about. On the Internet, a cookie is a text file used to save some data about you in your PC by a webpage. Why would a webpage want to do that? Normally to identify you or to remember some options you chosed and use them in the future. In fact, lots of pages use cookies to identify you as a unique user and that is why without…
Read More

Accesing a page element using JavaScript

Web standards
Lately I feel like making a master about selectors but I promise this is only a coincidence. When working with javascript we need to select the element we want to use and we have many ways to do so, I was wondering which one is the better to use so I wondered and found an answer to this issue. Let's see the alternatives: [sourcecode language="js" wraplines="false"] alert(document.forms[0].elements[0].value); alert(document.forms["myForm"].elements["myInputText"].value); alert(document.myForm.myInputText.value); alert(document.getElementById('myInputText').value); [/sourcecode] The first option just moves across the document objects and knowing the position let us get the object we want with its value or other properties. This option is really risky since in case you change something in the page and add more forms or elements before the one selected it will not be at the same position anymore…
Read More

Introduction to jQuery

Web programming
To use jQuery we need to get the library from one of those sites hosting it, for example the JQuery project page, or use the Google Libraries API. We can call the online versions and save server resources or better have our own version to make sure it never goes off. jQuery library has methods, selectors and events to interact with the page objects and let you make some very nice effects, change or add styles and some other issues with no effort at all. I am going to have a look at it with the basics to get initiated into this amazing library. Selectors First of all, to interact with the page objects we need to select them, so that we can know with which object we are working.…
Read More

CSS Selectors to have in mind

Web design, Web standards
Here there are a few CSS selectors to have in mind when styling as some of them can save you a lot of time. Have in mind that some of them do not have full compatibility with every existing browser though. X > Y [sourcecode language="css" wraplines="false"] div#container > ul { border: 1px solid black; } [/sourcecode] This type of selector may be really useful. It lets you establish the style of direct children of an element. Look at this code: [sourcecode language="html" wraplines="false"] <div id="container"> <ul> <li> List Item <ul> <li> Child </li> </ul> </li> <li> List Item </li> <li> List Item </li> <li> List Item </li> </ul> </div> [/sourcecode] With the X > Y you can say you want an special style for lists in #container but not…
Read More

Reading blog feed using PHP

Web programming
Well, once I made the last post about how to read a blog feed in ASP.Net using LINQ I just wondered if I would be able to do it in PHP too, so I did it. Here's the code: [sourcecode language="php" wraplines="false"] function getBlogFeed($urlRSS) { $doc = new DOMDocument(); $doc->load($urlRSS); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node): $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); endforeach; return $arrFeeds; } [/sourcecode] Once you have that done you can just show it as you wish, this is my show function but have in mind it uses my css styles (you can have a look at how it looks at my home page). [sourcecode language="php" wraplines="false"] function showBlogFeed($urlRSS){ if ($urlRSS !== ''):…
Read More

Reading blog feed in Atom or RSS with LINQ

Web programming
One of the most practical features a blog has its the possibility of requesting the latest posts from another webpage to read it without the need of accessing its current webpage. For doing this crazy idea blogs use XML technology, the REST protocol and one of the syndication standards like RSS, RSS2.0, Atom or RDF. In this case I am going to use RSS2.0 to request the feed of my blog and I will manage it with Linq so that I will have a collection of my latest posts in a few lines. Let's see the code: [sourcecode language="vb" wraplines="false"] Private Sub readBlogRSS20() Dim feed As XDocument = XDocument.Load("http://www.rubencanton.com/blog/feed/") Dim sum = From item In feed.Element("rss").Element("channel").Elements("item") _ Select New BlogArticle(item.Element("title"), item.Element("link"), _ item.Element("pubDate"), item.Element("description")) End Sub [/sourcecode] I just load…
Read More

Birth, life and death of XHTML

Web standards
Before XHTML was the egg, no no, the chicken, well ok it was HTML 4.01. HTML was good, flexible, practical, allowed developers to do many things (and to not closing them), and despite its shortcomings we were happy, web developers used the font tag to apply styles and web browsers interpreted what they wanted. But then a new technology arrived, XML, allowing to create your own markup language, which means that you can create your own HTML (HTML is a programming language that works with labels, so that if I put a text between the labels <b> and </b> it will appear in bold). With XML you could make your own and custom HTML, with the tags that pleased you, you might even have HTML in Spanish! <negrita>esto está en…
Read More

Extension methods in C#.Net

Web programming
One very useful thing we have in .Net technology is the possibility of extending it's classes to have our own and useful methods to work with. For example, imagine I need to show the user name in the project saying hello, something like this: "Hello Ruben!". But, I do not know if the name is stored in the database in lowercase, uppercase or how. So, I am going to capitalize it to be sure: [sourcecode language="csharp" wraplines="false"] public void SayHello() { string userName = "ruben"; Console.WriteLine(userName.Capitalize()); } [/sourcecode] But, Oops! We have a problem. The method Capitalize does not exist in C# string class, so we cannot just capitalize it with an instruction and we are going to need to make a library which we'll have to call always to…
Read More

Readonly vs Const in C#.Net

Web programming
In C#.Net we have two ways to establish a value that is constant (which means that its value will not be modifiable). The first way is the old one, making a const variable (maybe you know it as #define), the second one is to make a readonly variable. The most important difference between them is that a const will be evaluated at compile time while a readonly variable will be evaluated at run time. This limits the possibilities with consts since you cannot, for example, declare const structures, as they will need to call a constructor and that has to be made in run time, but you still can attach some expressions to it as soon as it can be resolved in compilation time. [sourcecode language="csharp" wraplines="false"] public const int…
Read More

Using LINQ in VB.Net for selecting encoded data

Web programming
Between the multiple advantages which offers LINQ I think there's the possibility of reselect some data you have in cache or RAM so you don't need to send another request to the database. I was programming a little personal application in VB.Net yesterday and found myself with a little problem. I am saving some data encoded in base64 in the database and I want to have the option to filter and show only the ones which match. The problem came when I realized that, of course, having the data encoded in the Access DB I couldn't just use a "LIKE" to filter the selection, since the characters are not as they really are. First of all I thought on decoding the data in the DB and then filter but I…
Read More

Content relevance. Let’s use some colors

Web design, Web usability
This is a translation from my original post in spanish. I hope you like it! We are planning a new design for our website and doubt between using blue, red, pink, yellow, ... What would be better? What if I put bright pink edges? Surely no one would forget my web ... All the ones who have built a website once have gone through this process. What color to choose? Why can't I just put fluorescent orange background? Well, some things seem obvious, but others less so. I will try to order some ideas on this issue in this post. When designing a website, the first thing you have to think about is what is it's objective, from that point, try to steer the user towards this goal. For example,…
Read More

Asynchronous request with JavaScript: home-made AJAX

Web programming
This is a translation from my original post in spanish. I hope you enjoy it! Note: Original post had code in HTML, sorry if I missed something. A few days ago I was building a module that should make asynchronous requests to a webservice using javascript, in other words, the famous AJAX but manually made, without using any library. For those who do not know what AJAX is, it's what allows server requests without having to load the entire page. Surely you've seen it in many places, for example, when posting a comment on a blog which is posted and shown without a full reload of the page. So, in order to do this we need to use the XMLHttpRequest object of our browser using JavaScript and send a request…
Read More

Testing LINQ performance with ASP.Net

Web programming
This post its a translation from my original post in spanish. I hope you enjoy it! :) After learning the basics about LINQ and how it works, I had no choice but to test if, not only does it simplifies the code but also improves its efficiency. I decided to test the reading speed of XML files with LINQ and determine which one has a better reading speed: .Net XML access library or its new technology, LINQ. To that purpose, I built an XML with 100.000 registers which simulates a table with students data and I will send some requests. (more…)
Read More

How to throw a pop-up properly with Javascript

Web programming, Web standards
This is a translation from my original post in spanish. Hope you enjoy it! In some cases it can be useful for us and even more comfortable for the user to open a page in a pop-up on which to show the information. If we search in Google how to do it or read any javascript manual the code that will be shown its this one: [sourcecode language="js" wraplines="false"] window.open('url to open','window name','attribute1,attribute2') [/sourcecode] In fact, that code has some mistakes, lets see: Browsers without Javascript will cannot open the page. It will not be crawled correctly by searchers, and some crawlers, will not know how to follow it. When going over it with the mouse we will not see the url on our browser status bar. The user loses…
Read More