【问题标题】:Iframe with javascript and Chrome \ CMS ad managmentiframe 与 javascript 和 Chrome \ CMS 和管理
【发布时间】:2012-06-07 11:56:57
【问题描述】:

我有一个 CMS 系统,并且我选择了管理广告的选项。现在我有一个文本框,可以在其中粘贴他们的代码,我希望快速显示广告,以便他们可以看到广告以及它是否有效。问题如下:problem to display dynamically a javascript google ad in an iframe using jquery(阅读第一个答案)。

我想知道是否有可能做到这一点,或者唯一的选择是他们只能粘贴代码,但从 CMS 本身看不到它的实际效果。

编辑 我正在添加代码:

    <div class="block" data="500" style="margin-top: 5px; height: 644px;">
    <span class="brow" style="float: right;"><span class="label pla">תצוגה מקדימה:</span><div class="dprev"></div></span>
    <span class="brow" style="float: left; margin-top: 0;"><span class="label">הקוד:</span><br />
    <form action="pages/ad.php" target="preview1" method="post">
        <textarea data="1" name="textbox" class="dcode" style="float: none; resize: none; width: 312px; height: 543px;">
            <div style="width:160px;border:solid 1px #E5E5E5">
            <INPUT id="merlin_q3" type="hidden" value="1">
            <SCRIPT type=text/javascript>
            function fnMerlinAddUrl(qStr,val) {
            try{return('&' + qStr + '=' + val)}
            catch(e){}
            }
            //params
            merlin_partnerid = "3541";
            merlin_search="q3";
            merlin_search_result= '6';
            merlin_start_offset= 0;
            merlin_cols = '1';
            merlin_lang="heb";
            merlin_width ="90%";
            merlin_url = "" ;
            merlin_AdType="short_title_heb";
            merlin_Iframe_Unique_Index="3";
            merlin_default = "1";
            merlin_decodeKeyword = escape(document.getElementById("merlin_q3").value);
            var path='http://www.merlin.co.il/merlin_3rdparty/merlin_3rdparty.asp'; //&all=news
            merlin_url=path+"?utf=0&fixed=marimedia&modaa=mo"+fnMerlinAddUrl("partnerid",merlin_partnerid);
            merlin_url+=fnMerlinAddUrl("lang",merlin_lang);
            merlin_url+=fnMerlinAddUrl("AdType",merlin_AdType);
            merlin_url+=fnMerlinAddUrl("qtyResult",merlin_search_result);
            merlin_url+=fnMerlinAddUrl("ScriptIndex",merlin_Iframe_Unique_Index);
            merlin_url+=fnMerlinAddUrl("start_offset",merlin_start_offset);
            merlin_url+=fnMerlinAddUrl("cols",merlin_cols);
            merlin_url+=fnMerlinAddUrl("merlin_default",merlin_default);
            merlin_url+='&q=' +merlin_decodeKeyword;
            merlin_url+='&urlTag='+ "http%3A%2F%2Ftracking.merlin.co.il%2Faff_c%3Foffer_id%3D58%26aff_id%3D1216%26file_id%3D1652";
            document.write("<table width=100%><tr><td valign=top id='Merlin_tdInsert3'></td></tr></table>");
            var MerlinSS_OBJ=document.getElementsByTagName("HEAD");
            if(!MerlinSS_OBJ)document.createElement('HEAD');
            var  oScript= document.createElement("script");
            oScript.setAttribute("src",merlin_url); 
            document.getElementsByTagName("HEAD")[0].appendChild(oScript);
            </SCRIPT>
            </div><img src="http://tracking.merlin.co.il/aff_i?offer_id=58&aff_id=1216&file_id=1652" width="1" height="1">
        </textarea>
    </form></span>
    <button style="position: absolute; margin-right: 330px; bottom: 14px;"><img src="img/v.png" style="margin-top: -2px; margin-left: 2px;" alt="add" height="28"/>שמור שינויים</button>
</div>
<h1 style="margin-top: -45px; position: relative;right: 574px;">פרסומת 2:</h1>
<div class="block" data="500" style="margin-right: 45px; height: 644px; margin-top: 5px;">
    <span class="brow" style="float: right;"><span class="label pla">תצוגה מקדימה:</span><div class="dprev"></div></span>
    <span class="brow" style="float: left; margin-top: 0;"><span class="label">הקוד:</span><br />
    <form action="pages/ad.php" target="preview2" method="POST">    
        <textarea data="2" class="dcode" style="float: none; resize: none; width: 312px; height: 543px;">
            <script type="text/javascript"><!--
            google_ad_client = "pub-2151667935419035";
            /* 120x600, created 7/17/08 */
            google_ad_slot = "8233032726";
            google_ad_width = 120;
            google_ad_height = 600;
            //-->
            </script>
            <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
            </script>
        </textarea>
    </form></span>
    <button style="position: absolute; margin-right: 330px; bottom: 14px;"><img 

    src="img/v.png" style="margin-top: -2px; margin-left: 2px;" alt="add" height="28"/>שמור שינויים</button>
    </div>
    <script>
    $("textarea.dcode").each(function (){
        $(this).closest("div").children("span:first-child").children("div.dprev").html('<iframe class="adprev" name="preview'+$(this).attr("data")+'" src="pages/ad.php"></iframe>');
        $(this).val($(this).text());
        $('form[target="preview'+$(this).attr("data")+'"]').submit();
    }).keyup(function (){
        $(this).closest("div").children("span:first-child").children("div.dprev").html('<iframe class="adprev" name="preview'+$(this).attr("data")+'" src="pages/ad.php"></iframe>');
        $('form[target="preview'+$(this).attr("data")+'"]').submit();
    });
    </script>

那里还有其他一些语言,但这并不重要,因为您可以看到我有两个 iframe,但代码仅适用于第一个。 (第一个是梅林广告,第二个是谷歌广告,但即使我把梅林放在第二个文本框中也不起作用)。

【问题讨论】:

    标签: javascript jquery google-chrome iframe content-management-system


    【解决方案1】:

    我自己没有尝试过这个解决方案,但您可能需要这样做:

    1. 使用来自您服务器的 url 创建动态 iframe,并将您的文本框值传递给那里(比如说iframe1.html?textbox=&lt;encoded text from the textbox&gt;)。这将是允许的,就像您在同一个域中那样。
    2. 在服务器上渲染iframe1.html 时再插入一个 iframe,其中包含您现在尝试执行的操作。现在对浏览器来说这似乎是静态的!
    3. 您将在 iframe 中拥有 iframe。但是你不会再通过javascript创建跨域iframe了。
    4. 利润!

    希望它会有所帮助!如果可以,请告诉我,我自己也很感兴趣)

    【讨论】:

    • 嘿,谢谢您的回答,我认为它可以工作我的问题是我不知道如何将字符串放入 get 属性中,似乎字符串中的 " 和 ' 关闭了src artibute...到目前为止我试过这个:$(this).closest("div").children("span:first-child").children("div.dprev").html('&lt;iframe src="pages/ad.php?textbox='+escape($(this).text())+'"&gt;&lt;/iframe&gt;');
    • 您不必这样做,那将是自动生成的字符串。检查此链接:(复制并粘贴,我无法在此处粘贴)https://twitter.com/share?original_referer=&amp;source=tweetbutton&amp;text=i am a string inside the get parameter&amp;url=。请务必避开&amp;= 之类的符号。
    • 其实你可以用 POST-data 做到这一点,那会更好:stackoverflow.com/questions/168455/how-do-you-post-to-an-iframe
    • 它有效,问题是它仅在第一个 iframe 上有效。我编辑问题以便您可以看到所有代码,请帮助 :)
    • 我没有'ad.php'脚本,所以我自己看不到。但问题是(我以前不知道)google adsense 禁用了 iframe 视图(support.google.com/adsense/bin/answer.py?hl=en&answer=48182,搜索“iframe”)。所以也许尝试用“div”替换“iframe”?
    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 2013-09-05
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多