RegisterStartupScript and Firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RHVuZTg4?=

    RegisterStartupScript and Firefox

    I've got some code that uses Page.ClientScri pt.RegisterStar tupScript to call
    a javascript function from the Page_Load method in the code behind.

    The code works fine in IE but the javascript function is not called at all
    in Firefox. I stripped my code back to the basics and all I have now is a
    webform with no controls on it and the following in the code behind:

    protected void Page_Load(objec t sender, EventArgs e)
    {
    Page.ClientScri pt.RegisterStar tupScript(typeo f(Page),
    "TestScript ", "<script type='text/jscript'>alert( 'test script');</script>");
    }

    This very basic webform works in IE but not in Firefox.

    I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
    "onload="alert( 'onLoad')"" to the body tag to ensure that javascript was
    enabled and popups were not being blocked in Firefox. The onLoad alert came
    up fine but the alert added by the RegisterStartup Script did not come up.

    Can anyone shed any light on this?

    Cheers
  • Jonathan Wood

    #2
    Re: RegisterStartup Script and Firefox

    I haven't done much with RegisterStartup Script but it might be helpful to
    see what the resulting HTML is, especially if you've narrowed it down to a
    bare-bones page.

    --
    Jonathan Wood
    SoftCircuits Programming


    "Dune88" <Dune88@discuss ions.microsoft. comwrote in message
    news:FDE8F932-5601-4F7F-874C-8AADF3EA9FE4@mi crosoft.com...
    I've got some code that uses Page.ClientScri pt.RegisterStar tupScript to
    call
    a javascript function from the Page_Load method in the code behind.
    >
    The code works fine in IE but the javascript function is not called at all
    in Firefox. I stripped my code back to the basics and all I have now is a
    webform with no controls on it and the following in the code behind:
    >
    protected void Page_Load(objec t sender, EventArgs e)
    {
    Page.ClientScri pt.RegisterStar tupScript(typeo f(Page),
    "TestScript ", "<script type='text/jscript'>alert( 'test
    script');</script>");
    }
    >
    This very basic webform works in IE but not in Firefox.
    >
    I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
    "onload="alert( 'onLoad')"" to the body tag to ensure that javascript was
    enabled and popups were not being blocked in Firefox. The onLoad alert
    came
    up fine but the alert added by the RegisterStartup Script did not come up.
    >
    Can anyone shed any light on this?
    >
    Cheers

    Comment

    • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

      #3
      RE: RegisterStartup Script and Firefox

      How about trying:
      script type='text/javascript'

      "jscript" is Microsoft - specific and the kind people at Firefox apparently
      don't take kindly to it.
      -- Peter
      Site: http://www.eggheadcafe.com
      UnBlog: http://petesbloggerama.blogspot.com
      MetaFinder: http://www.blogmetafinder.com


      "Dune88" wrote:
      I've got some code that uses Page.ClientScri pt.RegisterStar tupScript to call
      a javascript function from the Page_Load method in the code behind.
      >
      The code works fine in IE but the javascript function is not called at all
      in Firefox. I stripped my code back to the basics and all I have now is a
      webform with no controls on it and the following in the code behind:
      >
      protected void Page_Load(objec t sender, EventArgs e)
      {
      Page.ClientScri pt.RegisterStar tupScript(typeo f(Page),
      "TestScript ", "<script type='text/jscript'>alert( 'test script');</script>");
      }
      >
      This very basic webform works in IE but not in Firefox.
      >
      I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
      "onload="alert( 'onLoad')"" to the body tag to ensure that javascript was
      enabled and popups were not being blocked in Firefox. The onLoad alert came
      up fine but the alert added by the RegisterStartup Script did not come up.
      >
      Can anyone shed any light on this?
      >
      Cheers

      Comment

      • Mark Rae [MVP]

        #4
        Re: RegisterStartup Script and Firefox

        "Dune88" <Dune88@discuss ions.microsoft. comwrote in message
        news:FDE8F932-5601-4F7F-874C-8AADF3EA9FE4@mi crosoft.com...
        protected void Page_Load(objec t sender, EventArgs e)
        {
        Page.ClientScri pt.RegisterStar tupScript(typeo f(Page),
        "TestScript ", "<script type='text/jscript'>alert( 'test
        script');</script>");
        }
        >
        This very basic webform works in IE but not in Firefox.
        >
        I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
        "onload="alert( 'onLoad')"" to the body tag to ensure that javascript was
        enabled and popups were not being blocked in Firefox. The onLoad alert
        came
        up fine but the alert added by the RegisterStartup Script did not come up.
        >
        Can anyone shed any light on this?
        That's because you're telling the browser that it should process a script
        type of text/jscript - that will only work in IE, Opera and Safari:


        If you *must* include the script tags, make sure you use
        type='text/javascript', which will also work in FireFox etc...

        However, it's much safer to let ASP.NET output the script tags dynamically
        according to what browser it detects, by using the boolean overload of the
        RegisterStartup Script method:
        ClientScript.Re gisterStartupSc ript(typeof(Pag e), "TestScript ", "alert('tes t
        script');", True);


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • =?Utf-8?B?RHVuZTg4?=

          #5
          Re: RegisterStartup Script and Firefox

          Thanks for all the replies!

          Changing "jscript" to "javascript " worked perfectly as did using the boolean
          overload.

          Doh! I should have spotted that earlier!

          "Mark Rae [MVP]" wrote:
          "Dune88" <Dune88@discuss ions.microsoft. comwrote in message
          news:FDE8F932-5601-4F7F-874C-8AADF3EA9FE4@mi crosoft.com...
          >
          protected void Page_Load(objec t sender, EventArgs e)
          {
          Page.ClientScri pt.RegisterStar tupScript(typeo f(Page),
          "TestScript ", "<script type='text/jscript'>alert( 'test
          script');</script>");
          }

          This very basic webform works in IE but not in Firefox.

          I'm running .NET Framework 3.5, IE 7 and Firefox 2.0.0.11. I added
          "onload="alert( 'onLoad')"" to the body tag to ensure that javascript was
          enabled and popups were not being blocked in Firefox. The onLoad alert
          came
          up fine but the alert added by the RegisterStartup Script did not come up.

          Can anyone shed any light on this?
          >
          That's because you're telling the browser that it should process a script
          type of text/jscript - that will only work in IE, Opera and Safari:

          >
          If you *must* include the script tags, make sure you use
          type='text/javascript', which will also work in FireFox etc...
          >
          However, it's much safer to let ASP.NET output the script tags dynamically
          according to what browser it detects, by using the boolean overload of the
          RegisterStartup Script method:
          ClientScript.Re gisterStartupSc ript(typeof(Pag e), "TestScript ", "alert('tes t
          script');", True);
          >
          >
          --
          Mark Rae
          ASP.NET MVP

          >
          >

          Comment

          Working...