quote problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don Crossman

    #1

    quote problem

    Can someone tell me how to get this line to work?

    document.write (" <input type='button' value='Make this your home
    page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
    this.setHomePag e("http://www.somewhere.c om");' />");

    Seems no matter what I try, it either throws an error (expected ')'), or
    just does nothing. It would seem that escaping is not the answer in this
    case (it didn't work).

    I only want this button to show if the browser is IE 5+ for obvious
    reasons.

    The entire script:
    <script type="text/javascript">
    if (navigator.appN ame == "Microsoft Internet Explorer" &&
    navigator.appVe rsion >= "5.0") {
    document.write ("<form>");
    document.write (" <div align='center'> ");
    document.write (" <input type='button' value='Make this your home
    page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
    this.setHomePag e("http://www.somewhere.c om");' />");
    document.write (" </div>");
    document.write ("</form>");
    }
    </script>

    Thanks.

    -- Don
  • kaeli

    #2
    Re: quote problem

    In article <Xns948D5BEB75C 24dcrossmannosp amemail@216.168 .3.44>,
    dcrossman@nospa m.email.com enlightened us with...[color=blue]
    > Can someone tell me how to get this line to work?
    >[/color]


    Browser detection sucks.
    Use conditional IE comments to target IE only.

    http://msdn.microsoft.com/library/default.asp?
    url=/workshop/author/dhtml/overview/ccomment_ovw.as p

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title> New Document </title>

    </head>

    <body>
    test
    <!--[if gte IE 5]>
    <input type='button' value='Make this your home page'
    onclick='this.s tyle.behavior=" url(#default#ho mepage)";
    this.setHomePag e("http://www.somewhere.c om");' />
    <![endif]-->
    </body>
    </html>

    --
    --
    ~kaeli~
    Experience is something you don't get until just after you
    need it.



    Comment

    • Cycloneous Echevarria

      #3
      Re: quote problem

      Don:

      document.write ("<input type='button' value='Make this your home page'
      onclick='this.s tyle.behavior=\ "url(#default#h omepage)\";
      this.setHomePag e(\"http://www.somewhere.c om\");'/>");

      You have to escape the quotes.

      Orlando, aka, Cycloneous


      Don Crossman wrote:
      [color=blue]
      > Can someone tell me how to get this line to work?
      >
      > document.write (" <input type='button' value='Make this your home
      > page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
      > this.setHomePag e("http://www.somewhere.c om");' />");
      >
      > Seems no matter what I try, it either throws an error (expected ')'), or
      > just does nothing. It would seem that escaping is not the answer in this
      > case (it didn't work).
      >
      > I only want this button to show if the browser is IE 5+ for obvious
      > reasons.
      >
      > The entire script:
      > <script type="text/javascript">
      > if (navigator.appN ame == "Microsoft Internet Explorer" &&
      > navigator.appVe rsion >= "5.0") {
      > document.write ("<form>");
      > document.write (" <div align='center'> ");
      > document.write (" <input type='button' value='Make this your home
      > page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
      > this.setHomePag e("http://www.somewhere.c om");' />");
      > document.write (" </div>");
      > document.write ("</form>");
      > }
      > </script>
      >
      > Thanks.
      >
      > -- Don[/color]

      Comment

      • Don Crossman

        #4
        Re: quote problem

        You're right. Actually, the problem is something screwy in the if
        statement. The script bails in IE 6.

        Cycloneous Echevarria <orlando@engr.u conn.edu> wrote in
        news:UlPWb.2071 3$y64.19893@new ssvr16.news.pro digy.com:
        [color=blue]
        > Don:
        >
        > document.write ("<input type='button' value='Make this your home page'
        > onclick='this.s tyle.behavior=\ "url(#default#h omepage)\";
        > this.setHomePag e(\"http://www.somewhere.c om\");'/>");
        >
        > You have to escape the quotes.
        >
        > Orlando, aka, Cycloneous
        >
        >
        > Don Crossman wrote:
        >[color=green]
        >> Can someone tell me how to get this line to work?
        >>
        >> document.write (" <input type='button' value='Make this your home
        >> page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
        >> this.setHomePag e("http://www.somewhere.c om");' />");
        >>
        >> Seems no matter what I try, it either throws an error (expected ')'),
        >> or just does nothing. It would seem that escaping is not the answer
        >> in this case (it didn't work).
        >>
        >> I only want this button to show if the browser is IE 5+ for obvious
        >> reasons.
        >>
        >> The entire script:
        >> <script type="text/javascript">
        >> if (navigator.appN ame == "Microsoft Internet Explorer" &&
        >> navigator.appVe rsion >= "5.0") {
        >> document.write ("<form>");
        >> document.write (" <div align='center'> ");
        >> document.write (" <input type='button' value='Make this your
        >> home
        >> page' onclick='this.s tyle.behavior=" url(#default#ho mepage)";
        >> this.setHomePag e("http://www.somewhere.c om");' />");
        >> document.write (" </div>");
        >> document.write ("</form>");
        >> }
        >> </script>
        >>
        >> Thanks.
        >>
        >> -- Don[/color]
        >[/color]

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: quote problem

          ExGuardianReade r <noway@noway.co m> writes:

          (What are you answering?)
          [color=blue]
          > You can always use &#x22 to put a double quote character inside a
          > string, and &#x27 to put an apostrophe in.[/color]

          "Always" is too much. The string "&#x22" is an HTML entity. If your
          Javascript is not embedded in a HTML file, e.g., an external Javascript
          file, then it will not work.

          What will work is "\x22" inside a Javascript string literal. That is the
          Javascript escape, not the HTML one.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          Working...