0

I have a CMS system and I made an option to manage the ads. Now what I have is a textbox where the paste their code, and I want to have a fast display of the ad so they can see the ad and if it's working. The problem is like here: problem to display dynamically a javascript google ad in an iframe using jquery (read the first answer).

I was wondering if it's somehow possible to do it or the only option is that they can only paste the code, but don't see it in action from the CMS itself.

EDIT I'm adding the code:

    <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>

there is some other language there but that's not important, as you can see i have two iframes, but the code only works for the first. (first is merlin ads and second is google ads, but even i put the merlin in the second textbox it's not working).

Community
  • 1
  • 1
Dan Barzilay
  • 4,974
  • 5
  • 27
  • 39

1 Answers1

1

I have not tried this solution myself, but you will probably need to do something like this:

  1. Create dinamically iframe with the url from your server and pass there your textbox value (let's say iframe1.html?textbox=<encoded text from the textbox>). This will be allowed, as you do that in the same domain.
  2. On the server while rendering iframe1.html insert there one more iframe with what you try to do now. That would now seem static to browser!
  3. You will have iframe inside iframe. But you will not any more create cross-domain iframe by javascript.
  4. Profit!

Hope it will help! And if it will, please let me know, I am interested myself)

Dmitry Laptev
  • 371
  • 3
  • 12
  • Hey thank you for your answer, i think it can work my problam is that i dont know how can i put the string into the get property, it seems like the " and ' in the string close the src artibute... i tryed this so far: `$(this).closest("div").children("span:first-child").children("div.dprev").html('');` – Dan Barzilay Jun 07 '12 at 15:28
  • You don't have to do that, that would be the string automatically. Check this link: (copy and paste it, I cannot paste it here) `https://twitter.com/share?original_referer=&source=tweetbutton&text=i am a string inside the get parameter&url=`. Just be sure to escape some signes like `&` and `=`. – Dmitry Laptev Jun 07 '12 at 15:48
  • Actually you can probably do that with POST-data, that would be much better: http://stackoverflow.com/questions/168455/how-do-you-post-to-an-iframe – Dmitry Laptev Jun 07 '12 at 15:57
  • It works, the problam is that it's working only on the first iframe.. ill edit the question so you can see the all code, please help :) – Dan Barzilay Jun 08 '12 at 20:45
  • I have no 'ad.php' script, so I cannot see that myself. But the thing is (I didn't know that before) that google adsense disabled iframe view ( https://support.google.com/adsense/bin/answer.py?hl=en&answer=48182 , search for "iframe"). So maybe trying replace 'iframe' with just 'div'? – Dmitry Laptev Jun 09 '12 at 12:05
  • By the way, they still have it in iframe in Blogger.com preview window (in design section you can add there ads), but I don't know how they do it. – Dmitry Laptev Jun 09 '12 at 12:06
  • i dont have an adsense acount, so i can't check how it's working on blogger, do u have one? – Dan Barzilay Jun 09 '12 at 12:36
  • I tryed replacing the div with iframe but it seems the ad code has document.write in it and i found that if this command executes after the page had finished loading it just wipes the all page to white and than execute it so no good to me :( than i guess it's not really possible to make ads preview :( i wonder how other cms manage the ads... (oh and read the comment before please) – Dan Barzilay Jun 09 '12 at 13:02
  • So i checked some other cms and they just don't have a preview... :/ – Dan Barzilay Jun 09 '12 at 13:16
  • Ok so i checked the blogger, it doesn't really show the ads itself just a demo with some demo text for your ads allowing you to change colors etc... so you can't ill have to remove the preview :( – Dan Barzilay Jun 09 '12 at 13:21
  • Yes, I have tried to find something like this myself, but the only thing I can say at the moment, is that you can only reload the page to see the preview... I see no way to do that dinamically :( – Dmitry Laptev Jun 09 '12 at 13:27