Writing a backslash into the style tag

Discussion in 'Javascript' started by Yansky, Mar 27, 2007.

  1. Yansky

    Yansky Guest

    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.
     
    Yansky, Mar 27, 2007
    #1
    1. Advertising

  2. Yansky

    Weston Guest

    On Mar 27, 3:30 pm, "Yansky" <> 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); }');)?
     
    Weston, Mar 27, 2007
    #2
    1. Advertising

  3. Yansky

    VK Guest

    On Mar 27, 11:30 pm, "Yansky" <> 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>
     
    VK, Mar 27, 2007
    #3
  4. Yansky

    Yansky Guest

    On Mar 28, 6:07 am, "Weston" <notsew-
    > wrote:
    > On Mar 27, 3:30 pm, "Yansky" <> 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"
     
    Yansky, Mar 27, 2007
    #4
  5. Yansky

    Yansky Guest

    On Mar 28, 6:17 am, "VK" <> wrote:
    > On Mar 27, 11:30 pm, "Yansky" <> 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. :(
     
    Yansky, Mar 27, 2007
    #5
  6. Yansky

    Yansky Guest

    Yansky, Mar 28, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shurik
    Replies:
    1
    Views:
    340
    Steve
    Jan 3, 2006
  2. jstack
    Replies:
    1
    Views:
    611
    Tor Iver Wilhelmsen
    Jul 4, 2003
  3. shruds
    Replies:
    1
    Views:
    829
    John C. Bollinger
    Jan 27, 2006
  4. Vincent Texier
    Replies:
    3
    Views:
    2,273
    Vincent Texier
    Jul 1, 2004
  5. Ken Varn
    Replies:
    0
    Views:
    470
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page