ITmeze - IT world server like cyprus meze

Recent blog posts Tagged 'javascript'

Javascript Encode on server side - Medium Trust Environment

Itmeze

It happens from time to time I have to get rid of those funky apostrophe in my server/javascript code. To do such kind of things I was using Microsoft Anti-Cross Site Scripting Library. By simply calling:

public static string JavaSriptEncode(this string text) {
  return Microsoft.Security.Application.AntiXss.JavaScriptEncode(text, false);
}

Unfortunately, It doesn't work in Medium trust environment - btw, why the hell i get stingy clients. After some time digging all over internet and trying to write it by myself I accidentally found a thing that I never believed to be there. Well, ladies and gentleman, since .NET 4.0 HttpUtility has a new static function called... JavaScriptStringEncode

public static string JavaSriptEncode(this string text) {
  return HttpUtility.JavaScriptStringEncode(text);
}

Uff!...

Tags: [encoding] [javascript] [web development]

Noscript information with a link to google search

Itmeze

Some web apps just do not work without JavaScript. Just doesn't. Stop. We are usually asked to provide users with nice looking information that this site is best viewable with JavaScript turned on. Plus there is a need to explain them how to turn JS in their browsers. Smart and yet incredibly simple would be to direct them to google search result for a phrase like 'How do I enable JavaScript in my browser?'
<noscript>
  <a class="enable-js" href="http://www.google.com/search?q=How+do+I+enable+JavaScript+in+my+browser">
    XXX application requires JavaScript to be enabled in browser
  </a>
</noscript>
This one I use for most of web apps I have made so far. Smart, simple and always accurate. In fact that would be event nicer to add browser with version ...

Tags: [javascript] [noscript] [web development]

Copyright 2013 © ITmeze