Javascript related posts.

Dynamic Link Tag Injection

Using jquery to inject a style sheet seems to break IE7/8. The scenario was when a user passed in a custom param via the URL the code would inject that particular css. Ideally I should have gone with the native javascript way to create the element since it’s still clean and simple. This may not be an issue, but for my particular scenario it was the case.

jQuery version:

$('head').append($('<link rel="stylesheet" type="text/css" />')
         .attr('href', 'http://www.somedomain.com/css/cool.css'));

Native version:

var link = document.createElement('link');
    link.href = 'http://www.somedomain.com/css/cool.css';
    link.rel = 'stylesheet';
    link.type = 'text/css';

Working with NodeJS, CouchDB and Express Framework

This is a simple example of using node.js, nano (couch db modules) and the express framework to retrieve some data from a couch instance.

Setting up the modules

We will be using a couch instance from www.iriscouch.com. The database will be named “employees”.

We need to include the express module and create an express server:

With all modules setup it should look like this.

We need to give express access to the imgs, css and js directories so it can retrieve our assets.

Setting up a route

We are setting up a route to “all” that will call a view from the couch instance and retrieve some data.

Starting sever

Point your browser to http://localhost:3000/all. You should see a JSON object return like below. I only added 2 employees for the demo.

I will go over how to create a couch instance, create a view and add some data in another post.

Javascript Development Workflow Of 2013

© 2018 Aldomatic

Theme by Anders NorenUp ↑