Javascript code in classic asp

2019-07-25 05:39发布

问题:

Hello I have a JavaScript code and I want to use it in ASP file but my error code says:

Active Server Pages error 'ASP 0138'

Nested Script Block

/reklamsag.html, line 3

A script block cannot be placed inside another script block.

My code is:

<script src="http://ad.reklamport.com/scripts/rp.js" type="text/javascript"></script>
<script type="text/javascript">
    document.write("<script src='http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd="+Math.random()%99999999+"'></"+"script>");
</script>

Someone says use code in external file and include it asp file i use this include code but it didn't work:

<!--#include file="reklamsag.html"-->

回答1:

There is a technique to split the word "<script" into two parts such as "<scr" and "ipt" .

 document.write("<scr"+"ipt src....></scr"+"ipt>");

Your code can go like this:

<script src="http://ad.reklamport.com/scripts/rp.js" type="text/javascript"></script>
<script type="text/javascript">
    document.write("<scr"+"ipt src='http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd="+Math.random()%99999999+"'></"+"scr"+"ipt>");
</script>


回答2:

That's an incorrect way to load external JavaScript.

I understand the reasoning behind this is to prevent caching, since you already have server side language at your disposal, just have this and it will have the desired effect:

<script type="text/javascript" src="http://ad.reklamport.com/rpgetad.ashx?tt=t_canvecan_anasayfa_300x250&ciid=&rnd=<%=CLng(Timer())%>"></script>

This will append the amount of seconds since 12 AM, which is pretty much the same as random number. If you want extra layer or "uniqueness" you can add year, month and day.