Written by Calophi on
June 29, 2006 at 12:29 pm
Filed under Javascript, CSS · Trackback
This isn’t about rotating through alternate stylesheets or importing them, or even changing an inline style on an element through Javascript. Oh no. This is about creating an actually stylesheet element ON THE FLY.
The reason for this is because for a bit I was just trying to create a long string with the style tags and rules inside it, and then just pop it in the innerHTML of the body. (Hey, I’m no Guru, I have a lot to learn!) Needless to say, this caused a few issues.
(Read the rest of this entry »)
Tags: css, javascript
Permalink
Written by Calophi on
June 29, 2006 at 12:02 pm
Filed under Javascript, XML · Trackback
At work some of my tasks have led me to fooling around with new interface ideas. I figured this is a good way to get up to scratch with AJAX and related ideas.
Now if you’re pulling in XML with AJAX you know that it can be a perfect pain to parse the file. You’ve got to make sure that the file is converted into a document element (and the methods for doing so are unfortunately not cross-browser), and even afterwards there’s no cross-browser method to finding the tags you want - at least not one that will give you clean code. Basically, your choices are:
getElementsByTagName() - it works, but the function is long, and you’ll have more loops and nests than you can shake a stick at. Also, you’re limited to tags.
- Functions such as
firstChild and childNodes - which again, leads to long code and lots of nesting. Plus, using these you don’t even know what the tags are you’re messing with, and heaven forbid you change the XML schema a bit, if you didn’t well-document your javascript it could take you a bit to find the lines you need to alter.
- XPath and XSLT transformations - which are sadly not cross-browser and in some cases don’t even exist in certain browsers.
(Read the rest of this entry »)
Tags: No Tags
Permalink
Written by Calophi on
May 12, 2006 at 12:09 pm
Filed under Javascript, Regular Expressions · Trackback
I thought it might be nice to have a little archive of Javascript Regular Expressions for other people coming through.
This one is for pulling <script> tags out of a string. It should match any case, account for attributes in the opening tag, and match any code including line breaks in between the tags.
First up, a code to jut match an opening <script> tag, because any open <script> tag can screw up a page, so you might want to take care of just that:
/<[Ss]*?script(s[Ss]*?)?>/gi
Next, a tag to grab a <script> tag from beginning to end, so that you can protect all the text, or replace it, or what have you.
/<[Ss]*?script(s[Ss]*?)?>[Ss]*?<[Ss]*?/script(s[Ss]*?)?>/gi
Tags: No Tags
Permalink