Writing a backslash into the style tag

Y

Yansky

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.
 
W

Weston

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); }');)?
 
V

VK

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>
 
Y

Yansky

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"
 
Y

Yansky

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. :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top