to foreign server, aspx dynamically sending browser java script via <script src=

44 views Asked by At

Thank to you all in advance for helping. Here's something I have that is working up to a certain point.

From an html page on a foreign server (not mine) I have this HTML line

<script src="http://myserver.xyz/loadthis.aspx?BA_TYPE=1" type="text/javascript"></script>

"loadthis.aspx" page load event on my server contains this (I made it as simple as I can for this question, a lot more is happening in there but this is the subject of the question)

Response.Clear()
Response.Write("document.write('<a href= etc...")
Response.End()
Response.Close()

This works perfectly, dynamically loading the html

But I also need sometime to dynamically send a script like this one below instead.

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:90px"
         data-ad-client="ca-pub-8271739469826977"
         data-ad-slot="3666463954"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

I've tried things like this: where Str_BACODE as string containing the above code

Response.Write("document.write('" + StrBA_CODE + "')")
  • This does nothing. Do I need to use another javascript method replacing document.write?
  • Do I first need to modify the script I'm sending? Modifying what/how?

How could this be resolved?

Remember my routine(aspx) is used from other sites, not my server.

Hope I made this clear enough? Thanks! Steve

1

There are 1 answers

4
Khazratbek On

Use next:

Page.ClientScript.RegisterClientScriptInclude("MyTool", "http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js");
Response.Write(@"<ins class='adsbygoogle'
                 style='display:inline-block;width:728px;height:90px'
                 data-ad-client='ca-pub-8271739469826977'
                 data-ad-slot='3666463954'></ins>
                 <script>
                     (adsbygoogle = window.adsbygoogle || []).push({});
                 </script>");