This is a migrated thread and some comments may be shown as answers.

Adding script to head or top of body tag.

1 Answer 104 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Damodar
Top achievements
Rank 1
Damodar asked on 10 Nov 2014, 01:54 AM
Hi,

In one of the page we are trying to add script tag on the top of the head tag or on the top of the body tag.

That page contains wizard control and there are few steps.

We are adding different user controls in each steps.

We are able to put script tag in the first page load.
But from second step we are unable to add it.

<telerik:RadScriptBlock runat="server">
    <script type="text/javascript">
        $(document).ready(addScriptElement);
        function addScriptElement() {
                $('body').prepend(
                "<script id='transScript'>var dataLayer = dataLayer || [];dataLayer.push({'stepName': 'Details','stepVirtualURL': 'virtual-details'})<\/script>");
        };
    </script>
</telerik:RadScriptBlock>

We are using Master page.
Is there any ways we can do this? 

Best Regards,
Damodar

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Nov 2014, 11:39 AM
Hello Damador,

I suppose that you have Ajax enabled on the page and this is causing the presented behavior to appear. Note that   $(document).ready does not execute after Ajax calls.

Therefore in your case I would suggest you to implement the client logic int he client pageLoad event like this:
<telerik:RadScriptBlock runat="server">
    <script type="text/javascript">
        function pageLoad() {
                $('body').prepend(
                "<script id='transScript'>var dataLayer = dataLayer || [];dataLayer.push({'stepName': 'Details','stepVirtualURL': 'virtual-details'})<\/script>");
        };
    </script>
</telerik:RadScriptBlock>
 and see how it goes.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Damodar
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or