0

I get the ad from JSON response, response is below,for example I get below response from JSOn object like "ad"

<script type="text/javascript">
    document.write('<scr' + 'ipt src="//trk.diamondminebubble.com/h.html?e=hb_before_creative_renders&ho=2140340&ty=j&si=468x60&ta=16577&cd=cdn.marphezis.com&raid=4c56eeb6d&rimid=30af7b6d1&rbid=376879013&cb=' + Math.floor((Math.random() * 100000000000) + 1) + '&ref="></scr' + 'ipt>');
</script>
<script type="text/javascript">
    var compassSmartTag = {
        h: "2140340",
        t: "16577",
        d: "2",
        referral: "",
        y_b: {
            y: "j",
            s: "468x60"
        },
        hb: {
            raid: "4c56eeb6d",
            rimid: "30af7b6d1",
            rbid: "376879013"
        }
    };
</script>
<script src="//cdn.marphezis.com/cmps/cst.min.js"></script>
<img src="http://notifications.iselephant.com/hb/awin?byid=400&imid=30af7b6d1&auid=4c56eeb6d&bdid=376879013" width="1" height="1" style="display:none" />

I need to load this ad in particular below div,

<div id="newdiv"></div>
    document.getElementById('newdiv').innerHTML = ad;

The script loaded in div, but ad will not show. The above code just simply loads the script in the div. If the script will be run then only the ad will show. How do I run script after loaded to the div or is there any other way to show the ad in the div??? Any help is appreciated.

3
  • You are going to have problems loading a script via JSON that calls document.write Commented Jul 19, 2017 at 6:18
  • Is there anyother way to load and shown the image in div??? Commented Jul 19, 2017 at 6:24
  • Maybe you can embed your ad in Iframe in a separate page. The problem is document.write is going to clear your entire HTML document when you call it. Commented Jul 19, 2017 at 6:51

1 Answer 1

1

Given the issues with trying to load a <script> that is calling document.write through JSON your best option here may be to create a separate page, for example myAdPage.html.

In that page get the script with JSON and allow it to write its contents to that page.

You can then display the HTML of that page inside of an <iframe> inside of your <div>.

<div id="newdiv"><iframe src="myAdPage.html"></iframe></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.