escaping ampersands in UIBinder (adbrite script)

£可爱£侵袭症+ 提交于 2019-12-13 07:26:53

问题


I need to integrate the following script inside a div in UIBinder:

 <!-- Begin: adBrite, Generated: 2011-04-14 8:40:27  -->
 <script type="text/javascript">
 var AdBrite_Title_Color = '66B5FF';
 var AdBrite_Text_Color = '000000';
 var AdBrite_Background_Color = 'FFFFFF';
 var AdBrite_Border_Color = 'CCCCCC';
 var AdBrite_URL_Color = '008000';
 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=123&zs=123&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=123&afsid=1"><img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-leaderboard.gif" style="background-color:#CCCCCC;border:none;padding:0;margin:0;" alt="Your Ad Here" width="14" height="90" border="0" /></a></span>
 <!-- End: adBrite -->

The GWT compiler complains about the ampersands, so I changed them to &amp;.

I've also taken care to declare the following at the top of my file so that the ampersand entity can be properly resolved:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">

This at least allows me to compile the code, but the resulting page renders with &amp; instead of &, which of course breaks the script.

How can I properly escape the ampersands so that the script runs properly? Is there a way to declare this script in my loader html/jsp, and have it render into a div of my choosing? I couldn't find much documentation on Adbrite's site.

And lastly, is it truly necessary for Adbrite to try and hide the fact that the script is coming from a remote site with the String.fromCharCode nonsense? Presumably this is being done to prevent some kind of XSS filtering from kicking in.

Thanks


回答1:


Put your Javascript code between HTML comments. Replace & by &amp;.

Here is the code with the corrections:

<!-- Begin: adBrite, Generated: 2011-04-14 8:40:27 -->
        <script type="text/javascript"><!-- 
            var AdBrite_Title_Color = '66B5FF';
            var AdBrite_Text_Color = '000000';
            var AdBrite_Background_Color = 'FFFFFF';
            var AdBrite_Border_Color = 'CCCCCC';
            var AdBrite_URL_Color = '008000';
            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=123&zs=123&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=123&amp;afsid=1"><img src="http://files.adbrite.com/mb/images/adbrite-your-ad-here-leaderboard.gif" style="background-color:#CCCCCC;border:none;padding:0;margin:0;" alt="Your Ad Here" width="14" height="90" border="0" /></a></span>
        <!-- End: adBrite -->


来源:https://stackoverflow.com/questions/5667781/escaping-ampersands-in-uibinder-adbrite-script

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