0
<script type="text/javascript" src="http://example.com/show_ad.js"></script>

I put the line from above on multiple locations on the page. This script will put a iframe element on the page. The problem is that the script only loads once when I use this script multiple times. Does anyone have a solution for this?

Thanks already.

3
  • You'd have to talk to whomever wrote the script to see how they intended it to behave in this situation. Commented Sep 26, 2013 at 20:54
  • I wrote the script myself.. Commented Sep 26, 2013 at 20:55
  • 2
    there could be 100 reasons why something "only works once"; post the actual code for an actual answer. Commented Sep 26, 2013 at 21:03

2 Answers 2

1

Instead of adding script tags to the page every time you want to put an iframe on the page, why don't you just put the iframe there instead?

If you really want to use the method you're currently using, wrap show_ads.js code in some sort function (like var show_ads = function () {...}), and have additional javascript on the page to call this function when you need it, and capture the iframe. Then insert that iframe into the page at the spot that you want, instead of putting a script tag there.

Sign up to request clarification or add additional context in comments.

1 Comment

The reason why I use the script tags is because the website owner can't give me modification rights. So if I just give him the iframe tags then its not possible for me to change the size or source.
0

I stumbled across this article today, http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

It goes over how to sandbox 3rd party JavaScript files in iframes so that they don't conflict with each other & can't do anything malicious.

After viewing your comment that you wrote the script yourself, you may want to try wrapping your entire script in a closure. For example:

(function() {
 // script here
})();

It will ensure that globals you may have defined don't conflict / only exist within that closure.

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.