【问题标题】:How do i escape this code to work in JavaScript?如何转义此代码以在 JavaScript 中工作?
【发布时间】:2010-11-19 03:22:20
【问题描述】:
<!-- Begin: AdBrite, Generated: 2009-08-03 19:56:32  -->
<script type="text/javascript">
var AdBrite_Title_Color = '78B749';
var AdBrite_Text_Color = '000000';
var AdBrite_Background_Color = 'FFFFFF';
var AdBrite_Border_Color = 'CCCCCC';
var AdBrite_URL_Color = '0000FF';
try{
     var AdBrite_Iframe=window.top!=window.self?2:1;
      var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;
      AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);
 }catch(e){
      var AdBrite_Iframe='';
      var AdBrite_Referrer='';
 }
</script>
<span style="white-space:nowrap;">
 <script type="text/javascript">
 document.write(String.fromCharCode(60,83,67,82,73,80,84));
 document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=1287924&zs=3436385f3630&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');
 document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));
 </script>
<a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=1287924&afsid=1">
      <img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-banner.gif" style="background-color:#CCCCCC;border:none;padding:0;margin:0;" alt="Your Ad Here" width="11" height="60" border="0" />
 </a>
 </span>
<!-- End: AdBrite -->

我需要所有这些都被转义,我希望它不被 javascript 解释(我已经知道它的 javascript 本身,但我把这段代码放在不同的 javascript 文件中,我需要它来停止破坏脚本)。

编辑:stackoverflow 截断了一些代码。 =/ 转到http://uber-upload.com,查看源代码,搜索“中心>

【问题讨论】:

  • 我知道如何对字符串进行转义,但代码最后总是抓住我。

标签: javascript escaping


【解决方案1】:
【解决方案2】:

尝试转义双引号..(在 vim 中:%s/"/\"/g

document.write("var AdBrite_Title_Color = '78B749'; var AdBrite_Text_Color = '000000'; var AdBrite_Background_Color = 'FFFFFF'; var AdBrite_Border_Color = 'CCCCCC'; var AdBrite_URL_Color = '0000FF'; try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}\n\n"+"document.write(String.fromCharCode(60,83,67,82,73,80,84));document.write(' src=\"http://ads.adbrite.com/mb/text_group.php?sid=1287924&zs=3436385f3630&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'\" type=\"text/javascript\">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));");

【讨论】:

    【解决方案3】:

    你会使用 PHP 吗? This SO question 有一个可以解决问题的函数示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2020-01-07
      • 2015-05-17
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      相关资源
      最近更新 更多