Javascript code in classic asp

ぃ、小莉子 提交于 2019-12-11 07:35:47

问题


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.



来源:https://stackoverflow.com/questions/17108765/javascript-code-in-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!