Prototype and jQuery conflict resolution. Prototype JavaScript Library interferes with jQuery.
July 24, 2009 by MK
Filed under Javascript, web development
I experienced this conflict quite recently when I was working on WordPress Featured Articles Plugin. Normally jQuery.noConflict() comes to the rescue but not in my case. And the reason being - prototype was already interacting and was included at the top, so it was already using the $ variable.
This conflict causes the creation of the jQuery object to fail.
All the following errors are related to this conflict and you might get one or all of the following while using Prototype (Scriptaculous) and jQuery -
jQuery is not defined
$ is not a function
$ is not defined $(document).ready(function(){
Component returned failure code: 0×80040111 JavaScript error
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]” nsresult: “0×80004005 (NS_ERROR_FAILURE)”
What can we do to fix this?
You can try moving the jQuery.js to top and than use jQuery.noConflict().
If that is not an option you can do the following -
IMPORTANT - Do not use [REPLACE ALL]
- Edit prototype.js - find where it defines function $() and change the name to function $$$()
- Still in prototype.js, carefully replace each occurrence of $(…) with $$$(…), but don’t touch anything which says $$(…)
- Edit each of the other *.js files (e.g. effects.js) and carefully replace each occurrence of $(…) with $$$(…), but don’t touch anything which says $$(…).
- That is it.
And just in case you have trouble doing the above, Following links point to already edited prototype.js and effects.js. Please remember all the references to these files must start with $$$ instead of $.
Download - Prototype.js
Download - Effects.js
Hopefully this article will help some of our fellow coders and save them some time and frustration. Happy Coding guys :)
Apps running from Network Share run under Full Trust in .NET 3.5 SP1
July 16, 2009 by MK
Filed under C# / ASP.NET, web development
.NET 3.5 contains a change to the default grant set, applications launched from Local Intranet Zone will now run under Full Trust. This make the user experience and trust levels as if the app is launched from the local computer itself.
How this works?
When an .exe is launched directly off a network share, rather than giving it the Zone evidence of [Local Intranet], framework instead give the Zone evidence of [My Computer]. This causes the .exe to match the default [My Computer] code group rather than the [Local Intranet] group, and by default CAS policy grants Full Trust to that code group.
In addition to the entry point .exe of the application, framework also extend [My Computer] evidence to any assembly loaded from the same directory as the .exe. So, if you place any managed DLL’s immediately next to your .exe, those will also all be given Full Trust by default in .NET 3.5 SP1.
Will this work for DLL’s in sub directories?
And the answer is NO.
It will only work for assemblies loaded from the same directory as the entry point application. Apps that need to load assemblies from different sub directories or other network shares may not see all of their assemblies get fully trusted by default. For these type of applications, [Click Once] deployment is the recommended way to grant Full Trust.
Articles explaining Full Trust -
- What is ASP.NET Full trust hosting? and A few good Full trust hosting plans.
- Why Full Trust hosting is not recommended when using a shared ASP.NET or shared Windows hosting plan?
- How to grant Full Trust to your ASP.NET web site on your VPS / Dedicated Server
- Running Full Trust applications under Windows Azure.
- Microsoft Azure now supports PHP and allows full trust development
As per msdn web site -
Assemblies which will now receive Zone evidence of [My Computer] and therefore be fully trusted by default are:
- Any managed .exe which is launched directly from a network share
- Any assembly in that .exe’s process which is loaded from the same directory as the .exe itself was.
Assemblies which will not see this change include:
- Assemblies loaded from a subdirectory of the share where the .exe was launched from
- Assemblies loaded from shares other than the one where the main .exe was launched
- Any assembly loaded on a machine with the LegacyMyComputer registry value set to 1
- Any assembly loaded into a CLR host, including assemblies loaded into Internet Explorer as controls.
- Any assembly loaded from shares by an application that was launched from the "real" MyComputer zone.
What to expect in .NET 4 ?
In .NET 4.0 beta 1, Microsoft has significantly expanded this exemption, and all assemblies loaded by unhosted applications are fully trusted by default.
Running Full Trust applications under Windows Azure.
July 12, 2009 by MK
Filed under ASP.NET, Hosting, web development
What is Windows Azure?
Microsoft’s Azure Services Platform is a cloud platform (cloud computing platform as a service) offering that “provides a wide range of Internet services that can be consumed from both on-premises environments or the Internet (though the platform itself will not be made available for on-premises deployments.
To read more about Azure please visit Microsoft’s Official Website on Azure Services Platform.
What is Full Trust and why is it required?
Full trust (CAS - Code Access Security Level) allows ASP.NET applications to execute native code, to read from the Registry and Windows Event Log, and to read and write to files outside of the application’s virtual directory. In short, with full trust one web application could delete the entire contents of another web application.
To read more on Full Trust Hosting please visit What is ASP.NET Full trust hosting?
Looking for good Full Trust Windows / ASP.NET Hosting Plans - Try Webhost4life OR Alentus (We have been using them for years now)
Windows Azure and Full Trust.
Windows Azure now offers the option of running the code in your Web and Worker roles under full trust. As a developer this opens up a lot of exciting and compelling options -
- Inter-process Communication via Named Pipes:
If you application spawns processes, you can communicate among them via named pipes.
- Invoking non-.NET Code:
Many developers have existing investments in native code or may choose to use native code for some specialized tasks. .NET full trust makes it possible to use native code via spawning processes or Platform Invoke (P/Invoke).
- Using .NET Libraries that Require Full Trust:
Certain .NET libraries, including libraries in the .NET Services SDK, require full trust and can now be used in Windows Azure.
To enable full trust, simply add the enableNativeCodeExecution attribute to your role in the Service Definition file and set the attribute value to true:
<?xml version=”1.0″ encoding=”utf-8″?>
<ServiceDefinition name=”MyService” xmlns=”http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition”>
<WebRole name=”WebRole” enableNativeCodeExecution=”true”>
<InputEndpoints>
<InputEndpoint name=”HttpIn” protocol=”http” port=”80″ />
</InputEndpoints>
</WebRole>
</ServiceDefinition>
Windows Azure applications run with restricted “User” privileges in the cloud. Accordingly, certain operations such as modifying the registry and writing to the system directory are not possible at this time (even though they may succeed in your local development environment). To read more on more on Custom Trust visit Why Full Trust hosting is not recommended when using a shared ASP.NET or shared Windows hosting plan?
How to retain high resolution of a dynamically created image using ASP.NET and C#
March 27, 2009 by MK
Filed under C# / ASP.NET, web development
Today we will discuss about maintaining high resolution of dynamically created image using ASP.NET and C#. If you want to learn how to create an image - You can view this related article for creating an image dynamically using ASP.NET and C# (This article teaches about creating pie chart but can easily be altered to create any image).
This is a two step process -
First step is to define properties while declaring the Graphics class to be used for creating the image. Following properties can be used for attaining that -
objGraphics.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
objGraphics.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
objGraphics.CompositingQuality=System.Drawing.Drawing2D.CompositingQuality.HighQuality;
objGraphics.TextRenderingHint=System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
You can follow this link for more information on Graphics class and the properties used above - http://msdn.microsoft.com/en-us/library/system.drawing.graphics(VS.80).aspx
Second step is saving the image. For creating a high quality image we need to play around with the ImageCodecInfo class that we have created. Here we will loop through the MimeType property of encoders array and will select the matching MimeType.
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
Now we will define the response stream and the type of image we want to create.
using (System.Drawing.Image img = LoadImage()) //LoadImage() will return the image that we have created in the steps above.
{
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo(”image/jpeg”);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, 100L); //You can use 100L to increase or decrease the quality of the image.
myEncoderParameters.Param[0] = myEncoderParameter;
Response.ContentType = “image/gif”;
img.Save(Response.OutputStream, myImageCodecInfo, myEncoderParameters);
}
As you see its quite easy to create high quality images using the Graphics class in ASP.NET. Almost everything done by using third party components can be created using built in classes with ASP.NET. Happy Coding!!.
What is Bounce Rate? Seven easy steps to decrease the Bounce Rate of your Wordpress blog or website.
March 27, 2009 by MK
Filed under Blogging, Online Marketing, Wordpress, web development
In order to run a successful website you should know your site metrics. One key metric you should be aware of is Bounce Rate.
What is Bounce Rate?
Bounce rate is the percentage of single page visits or visits in which the person left your site from the entrance (landing) page. This entrance can be from any page on your site. Use this metric to measure visit quality - a high bounce rate generally indicates that site entrance pages are not relevant to your visitors.
If you haven’t been tracking your users, you should start now. Google Analytics is free and awesome. Google Analytics - You can sign up here
To view the bounce rates for your website using Google Analytics. Sign in and go to the Bounce Rate report under Visitors > Visitor Trending > Bounce Rate.
Why monitoring Bounce Rate Metrics is important?
Lets assume you own a physical electronics store.To run your store successfully you will require a lot of foot traffic and once your customers arrive you want them to make transactions. Or at least surf the store, you never know as they can find something interesting and useful while surfing that they would like to buy.
Same rule applies to the online world and this process of getting more traffic and converting them to sales is called conversion. You invite customers to your website by investing both time and money on good content, email and affiliate marketing, paid search etc. And once your online users hit your website you would like to capitalize on that investment.
Now this is where Bounce Rate Metric comes in handy. By measuring the bounce rate you can measure the effectiveness of your promotional marketing efforts. As you follow this metric at the landing page or the traffic source levels you can establish a baseline to track your success overtime.
We all spend a lot of money on conversions and this metrics can tell us where we are we acquiring quality traffic from and how successful we are on converting that traffic to sales or at the least have users stay on the site.
Bounce Rate metrics can be affected by a number of different variables. On an average bounce rate for your site should fall between 40 - 70%. You can not convince all the site traffic to stay but if your Bounce Rate is more then 70% you are doing something wrong.
Bounce rate is a great qualifying metric. Its a metric that helps you ask the right questions. Check the top web pages of your website from where people are entering the site and check there bounce rate. Remember as these pages are from where most of your online users are entering your site, you can determine by studying these pages if these pages are doing a good job.
How to bring down or decrease the bounce rate of your WordPress blog or website?
There are a number of measures that we can take to grab attention and compel users to stay on the site and thus decrease the bounce rate. I call them triggers or call to actions. Following are some of the steps that I follow rigorously and have been successful in decreasing the Bounce Rate for coolwebdeveloper.com over a period of time -
- Interesting Headline - Keep the title of your post interesting and should ignite quest to read the full post.
- Interactive Posts - Make your posts interactive by encouraging users to click on other useful links within your site. For example if you are writing a post on HP laptop, you can refer to previous posts you have written about HP laptop in this new article thus providing more options to your users.
- Best or Related Posts - Make sure your users can reach the Best or Related Posts from every page of your site.
Wordpress Plugin you can use - Yet Another Related Posts Plugin - BLOG’s design and SEO - Reconsider your blog’s navigation and overall theme design that could generate usability issues.
Thesis WordPress Theme
has the following functions automatically built in, so you do not need to use these plugins if you are using this theme. Just as an FYI - This theme is already getting some great reviews around the blogosphere (you can see some testimonials here). You can download Thesis Wordpress Theme here.
But if you are using other themes, the following plugins will give you a similar look/effect.
- All in One SEO Pack - This plugin makes it easy for you to optimize your article titles and other meta tags.
- Google Analytics - This plugin makes it easy for you to insert your Google Analytics code and start tracking your blog visitors.
- WP-Note - This plugin lets you insert notes in your article to make them stand out. Kind of similar to the yellow colored notes I have twice in this article.
- Wordpress Gravatars - This plugin lets you display Gravatars of your readers in the comments section and can put your Gravatar on top of your article to show who the article was written by.
- Error page - Make sure to use a 404 landing page on your blog or website. Users will hit this page if any link on your site is broken or not found. Using this page you can suggest your users about possible areas of site that can visit and might be interested in.
- Navigation - Easy to spot link to the Home Page. Use breadcrumbs feature for easier navigation. Categories and Posts should be easily visible on the site.
WordPress Plugin you can use - Breadcrumb Navigation - Not using relevant tags - One of the reasons why a lot of blogger’s and website owners have a high bounce rate is NOT using relevant tags while writing posts. Tag relevancy is very important. Users coming through Google or other sources are expecting to get the result based on there search keywqords. If you tags are not relevant, your bounce rate will definitely be higher.
- Incentive Offers - If you have something to give away like Free themes, free e-books, free reports etc then you will always be able attract visitors to click on that link.
- Interactive Elements - Use interactive elements that would require users to take small actions, such as polls.
By following these check points consistently you will be able to reduce the Bounce Rate of your site.
Do you have a high or a low bounce rate? How has the bounce rate affected your blog? What methods did you find most efficient to reduce the bounce rate? If you have suggestions or want to discuss more about Bounce Rate please leave your comments.














