473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Writing a backslash into the style tag

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.

Mar 27 '07 #1
5 1771
On Mar 27, 3:30 pm, "Yansky" <forbo...@gmail.comwrote:
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); }');)?

Mar 27 '07 #2
VK
On Mar 27, 11:30 pm, "Yansky" <forbo...@gmail.comwrote:
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 <htmlor <style>

Mar 27 '07 #3
On Mar 28, 6:07 am, "Weston" <notsew-
reversePreceedingAndRemoveT...@canncentral.orgwrot e:
On Mar 27, 3:30 pm, "Yansky" <forbo...@gmail.comwrote:
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"

Mar 27 '07 #4
On Mar 28, 6:17 am, "VK" <schools_r...@yahoo.comwrote:
On Mar 27, 11:30 pm, "Yansky" <forbo...@gmail.comwrote:
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 <htmlor <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. :(

Mar 27 '07 #5
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. :)

Mar 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terry Asher | last post by:
The following script does NOT escape the Apostrophe. Meaning when you mouseover the image the Alt tag says this: DMACC, It and then it stops. <SCRIPT Language="JavaScript"> var pos = "DMACC,...
3
by: Sathyaish | last post by:
In trying to replace character literals for their char constant, I am having difficulty printing the char constant for backslash. It instead prints the char literal. How do I resovle this? ...
19
by: Alan J. Flavell | last post by:
The story so far: on somewhat unrelated newsgroup, my attention fell upon the URL: http://www.speedtouchdsl.com/prod706.htm which contains a link to the purported URL:...
2
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
2
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
4
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an...
4
nithinpes
by: nithinpes | last post by:
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine. perl -ne "unless(//)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.