Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Writing a backslash into the style tag

Reply
Thread Tools

Writing a backslash into the style tag

 
 
Yansky
Guest
Posts: n/a
 
      03-27-2007
Hi, I'm trying to write a backslash as a text node into the style tag
of a web page, but IE is not letting me(perhaps because of security or
something?). I need to write a backslash because it is part of the
style rule needed to draw VML images. This is my current code at the
moment:


var theTextofStyle = document.createTextNode('v\:* { behavior:
url(#default#VML); }');
document.getElementsByTagName('style')[0].appendChild(theTextofStyle);

I've tried all the usual ways to escape the backslash, but IE still
won't let me write it into the style element.

Anyone have any ideas on getting around this?

Cheers.

 
Reply With Quote
 
 
 
 
Weston
Guest
Posts: n/a
 
      03-27-2007
On Mar 27, 3:30 pm, "Yansky" <(E-Mail Removed)> wrote:
> Hi, I'm trying to write a backslash as a text node into the style tag
> of a web page, but IE is not letting me(perhaps because of security or
> something?). I need to write a backslash because it is part of the
> style rule needed to draw VML images. This is my current code at the
> moment:
>
> var theTextofStyle = document.createTextNode('v\:* { behavior:
> url(#default#VML); }');
> document.getElementsByTagName('style')[0].appendChild(theTextofStyle);
>
> I've tried all the usual ways to escape the backslash, but IE still
> won't let me write it into the style element.
>
> Anyone have any ideas on getting around this?


What happens when you do the conventional c-slash escaping:

var theTextofStyle = document.createTextNode('v\\:* { behavior:
url(#default#VML); }')?





 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      03-27-2007
On Mar 27, 11:30 pm, "Yansky" <(E-Mail Removed)> wrote:
> This is my current code at the
> moment:
>
> var theTextofStyle = document.createTextNode('v\:* { behavior:
> url(#default#VML); }');
> document.getElementsByTagName('style')[0].appendChild(theTextofStyle);
>
> I've tried all the usual ways to escape the backslash, but IE still
> won't let me write it into the style element.
>
> Anyone have any ideas on getting around this?


Yes, I do. But just a year ago I would stay silent as it was the
biggest capitalization for myself out of simply reading producer
specs Now the retaining period is over. I am not saying that
I'm the only one who can read MSDN, but in this particular case it
seemed so for all the time of my interest.

First get rid of all this stuff you posted.

Now:

// missing namespaces return null
if (document.namespaces.item('v') == null) {
// then adding the required namespace/behavior combo:
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml',
'#default#VML');
}
// now you can draw whatever you want using VML

The page itself stays "clean" in the sense that you don't add any IE-
specific attributes into <html> or <style>

 
Reply With Quote
 
Yansky
Guest
Posts: n/a
 
      03-27-2007
On Mar 28, 6:07 am, "Weston" <notsew-
(E-Mail Removed)> wrote:
> On Mar 27, 3:30 pm, "Yansky" <(E-Mail Removed)> wrote:
>
> > Hi, I'm trying to write a backslash as a text node into the style tag
> > of a web page, but IE is not letting me(perhaps because of security or
> > something?). I need to write a backslash because it is part of the
> > style rule needed to draw VML images. This is my current code at the
> > moment:

>
> > var theTextofStyle = document.createTextNode('v\:* { behavior:
> > url(#default#VML); }');
> > document.getElementsByTagName('style')[0].appendChild(theTextofStyle);

>
> > I've tried all the usual ways to escape the backslash, but IE still
> > won't let me write it into the style element.

>
> > Anyone have any ideas on getting around this?

>
> What happens when you do the conventional c-slash escaping:
>
> var theTextofStyle = document.createTextNode('v\\:* { behavior:
> url(#default#VML); }')?


It still doesn't work. It gives me an error of "Object doesn't support
this property or method"

 
Reply With Quote
 
Yansky
Guest
Posts: n/a
 
      03-27-2007
On Mar 28, 6:17 am, "VK" <(E-Mail Removed)> wrote:
> On Mar 27, 11:30 pm, "Yansky" <(E-Mail Removed)> wrote:
>
> > This is my current code at the
> > moment:

>
> > var theTextofStyle = document.createTextNode('v\:* { behavior:
> > url(#default#VML); }');
> > document.getElementsByTagName('style')[0].appendChild(theTextofStyle);

>
> > I've tried all the usual ways to escape the backslash, but IE still
> > won't let me write it into the style element.

>
> > Anyone have any ideas on getting around this?

>
> Yes, I do. But just a year ago I would stay silent as it was the
> biggest capitalization for myself out of simply reading producer
> specs Now the retaining period is over. I am not saying that
> I'm the only one who can read MSDN, but in this particular case it
> seemed so for all the time of my interest.
>
> First get rid of all this stuff you posted.
>
> Now:
>
> // missing namespaces return null
> if (document.namespaces.item('v') == null) {
> // then adding the required namespace/behavior combo:
> document.namespaces.add('v', 'urn:schemas-microsoft-com:vml',
> '#default#VML');}
>
> // now you can draw whatever you want using VML
>
> The page itself stays "clean" in the sense that you don't add any IE-
> specific attributes into <html> or <style>


I've already got <html xmlns:v="urn:schemas-microsoft-com:vml" > as my
namespace, but the VML still doesn't seem to render unless I put v\:*
{ behavior:url(#default#VML); } in the style tag.

 
Reply With Quote
 
Yansky
Guest
Posts: n/a
 
      03-27-2007
I think I found a solution. There's an "IE specific"
createStyleSheet() function that was added in version 6. It's working
a treat.

http://msdn.microsoft.com/workshop/a...stylesheet.asp

Thanks for your replies anyway guys.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Image control emits arbitrary "style" into HTML tag??? Why??? Shurik ASP .Net 1 01-03-2006 08:00 PM
how to replace double backslash with one backslash in string... Vincent Texier Python 3 07-01-2004 01:03 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
How to embed the <jsp:plugin> tag into a tag handler class...HELP !! jstack Java 1 07-04-2003 06:58 PM



Advertisments