簡體   English   中英

如何從文本框中獲取javascript / html代碼

[英]How to get javascript/html Code as it is from a textbox

我想實現將adsense代碼存儲到sql數據庫的功能。 為此,我在文本框中使用了ajax:HtmlEditorExtender 現在我輸入此代碼

<script type="text/javascript"><!-- google_ad_client = "ca-pub-*****"; /* 728x90, created 6/12/02 */ google_ad_slot = "****"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead.googlesyndicaon.com/pead/show_ad.js"> </script>

現在的問題是當代碼插入數據庫時​​,上面的代碼轉換如下。

    &lt;pre&gt;&lt;<span>script</span> <span>type</span>="<a>text/javascript</a>"&gt;&lt;!--
    <span></span>google_ad_client = "ca-pub-*****";
    <span></span>/* 728x90, created 6/12/02 */
    <span></span>google_ad_slot = "****";
    <span></span>google_ad_width = 728;
    <span></span>google_ad_height = 90;
    <span></span>//--&gt;
    <span></span>&lt;/<span>script</span>&gt;
    <span></span>&lt;<span>script</span> <span>type</span>="<a>text/javascript</a>"
    <span></span><span>src</span>="<a href="view-source:http://pagead.googlesyndicaon.com/pead/show_ad.js">
http://pagead.googlesyndicaon.com/pead/show_ad.js</a>"&gt;
    <span></span>&lt;/<span>script</span>&gt;&lt;/pre&gt;

請幫幫我:

  1. 我應該怎么做,以便我可以將上部代碼存儲到數據庫中。
  2. 當代碼正確存儲到數據庫后,哪種控件最適合展示此廣告。(我是說我想在另一頁上展示廣告。)

提前致謝。

RE issue2:您可以使用普通的文本框並解碼字符串,或將其放回ajax:HtmlEditorExtender文本框,然后使用以下代碼(消毒程序可能已對所有標簽的開始和結束進行了編碼,等等。

Server.HtmlDecode(TextBox_Editor.Text)

回應您的評論:嘗試將解碼后的文本放入asp:label OnPreRender

編輯:嘗試使用HtmlAgilityPackSanitizerProvider,該最新程序包解決了圍繞消毒劑的某些“錯誤” ...閱讀此頁 ,Stephen Walters自己承認,默認消毒劑在剝離時過於激進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM