Monday, March 23, 2009

Posting javascript in blogger

I once tried to post some javascript inside the post itself and found out that it was not working.
Well seems like if you want to embed <script> tags inside the post, and you have "Convert line breaks" set to true (by default), you cannot add script tags, as Blogger would add <br /> instead of your line breaks.
So you need to write down your script in one single line.

Which is what this post actually does. Use it to your heart's content :)
Post your javascript here
>




Remove New Lines Remove Multiple spaces Replace <, > to &lt; and &gt; resp.






Enjoy :)

BTW, the javascript for the above is embedded in this post itself. And here's the code, use it on the above textarea ;-):


<script type="text/javascript">

function toggleCheckbox(docid) {
var rs = document.getElementById(docid);
rs.checked = !rs.checked;
}
function removeNewLines() {
var rnl = document.getElementById("removeNewLines");
var rs = document.getElementById("removeSpace");
var rlt = document.getElementById("replaceLt");
var c = document.getElementById('content').value;
var r = rl(c, rnl.checked, rs.checked, rlt.checked);
document.getElementById('result').value = r;
}

function rl(str, rnl, rs, rlt) {
if (rnl) {
str = str.replace(/[\n\r\t]/g,' ');
}
if (rs) {
str = str.replace(/ [ ]*/g,' ');
}
if (rlt) {
str = str.replace(/</g,'&lt;').replace(/>/g, '&gt;');
}
return str;
}
</script>

8 comments:

syed said...

atest

katty said...

JavaScript is a good program and very easy to use. I don´t like a complex program. I prefer javascript because i consider it like a device very eficient and it have a good quality.
I always looking for the quality that is why i prefer to buy viagra because i always have a great result in my sexual life.

Anonymous said...

Remarkable things here. I'm very satisfied to see your article. Thanks a lot and I'm looking ahead to
touch you. Will you please drop me a e-mail?


Also visit my page: Grow XL

Anonymous said...

Hello, its nice article concerning media print,
we all be aware of media is a great source
of information.

my web site :: Grow XL Reviews

Anonymous said...

Thank you for some other excellent post. Where else may anyone get
that type of info in such an ideal means of writing?
I've a presentation subsequent week, and I am at the search for such information.

Have a look at my web page; Muscle REv Xtreme REview

Anonymous said...

I all the time emailed this webpage post page to all my
associates, because if like to read it then my contacts will too.


My homepage Saphire Electronic Cigarette

Anonymous said...

Hi there it's me, I am also visiting this web page daily, this web page is actually nice and the visitors are genuinely sharing pleasant thoughts.

Here is my blog post: Lean Muscle formula

Anonymous said...

Wow, this post is nice, my younger sister is analyzing these things,
so I am going to inform her.

Also visit my site optimalstacks.net

Post a Comment