CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    [RESOLVED] dynamically load/change javascript

    I have a piece of javascript form alexa.com.

    Code:
    <script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/s/a?url=codeguru.com'></script>
    When I place this tag anywhere in the body (for example somewhere in a table), it works just fine. But the problem is, that I don't know how I can change the url dynamically.

    I know which url to show in the page_load, and I tried the next:
    Code:
             string url = Request.QueryString["url"];
             string script = string.Format("<script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/s/a?url={0}'></script>", url);
             Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script", script, false);
    This works, but the image produced by the javascript is placed on top of the page.

    How can I change this and place the image not on top of the page?

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: dynamically load/change javascript

    After lots of googling I found the solution. Actually it is really simple.

    Just use an asp:Literal control and change its text property

    Code:
    literalAlexa.Text = "<script type='text/javascript' language='JavaScript' src='http://xslt.alexa.com/site_stats/js/s/a?url=codeguru.com'></script>";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured