Getting the contents after the # character in the URL

Monday, February 16th, 2009

If you are trying to get the values after a # character in the url using PHP then you may not be able to do that using any of the PHP functions cause the # is not sent to the server.

In this situation, you can use a little Javascript to get only that part of the url which is after the # character by using

document.write(location.hash.slice(1));

PHP Rich text editor for Flash

Monday, January 19th, 2009

If you have created a rich text editor using Javascript’s execCommand and an IFRAME and you intend to use the output inside a Flash textfield, then you may have to change the output from your RTE for the bold, italic and underline commands.

execCommand() for making the selection inside the IFRAME bold will give out something like this:

  • <span style=”font-weight: bold;”>Bold text</span>

And flash expects it to be

  • <b>Bold text</b>

In this situation you can use a bit of regex to convert the style based <span> element to a <b> element like this

//get the content first
var rte_content = document.getElementById(‘rte_content’);
//put it in a string
var str = oRTE.document.body.innerHTML;

//replace the content
str = str.replace(/<span style=”font-weight: bold;”>(.+?)<\/span>/g,’<b>$1</b>’)

Now you can pass the ’str’ to a hidden form element or whichever way you are using to post the content. The same applies to italic and underline…

Solution for IE6 setAttribute bug

Saturday, October 6th, 2007

If you ve been trying to use the setAttribute function to dynamically change the properties of an HTML element and wondering what to do when it fails on Internet Explorer 6 then here s something that most definitely works:

var oDiv =  document.getElementById(“div_name”);

Instead of typing
oDiv.setAttribute(“style”, “color:#666;”);
Simply access that property directly by Javascript
oDiv.style.cssText = “background-color:#666″;

This works on ie6 ie7 and ff. I havent checked in Netscape.
I found this solution here

http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html

It is the 5th comment on the page by Rob.(http://blog.throbs.net/)

Rich Text Editor for CMS

Saturday, January 27th, 2007

I ve decided I m going to create one CMS system and use it for every project. Same with the shopping cart and the products section of any site. There is a bit of a mental debate regarding MySQL and XML but one of them should be soon finalized. The sole reason for considering XML is ‘it is portable’ and I still need to learn how to transfer a MySQL database from one server to another.

The objective of creating one CMS or shopping cart system is, once that is done then I can concentrate solely on design which is something that has not been done consciously for years now.

Anyway, any good CMS solution should have at least some basic text formatting options when users add content. The solution that I had provided earlier was: Above every ‘textarea’ where the user would insert content, I had written very proudly ‘Feel free to use HTML tags in here!’ Now that was some solution!

I have noticed that useless solutions dont make a big issue, they simply get ignored and die out on their own. So I started hunting for tutorials to make rich text editors for CMS. Fortunately, I came across the following link: http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm. It gave me just what I wanted: A text editor that generates code for whatever formating the user does inside the textarea.

Though I still havent checked if the same code gets converted into formatted textarea while editing it!