I want to add from iframe window a custom javascript function to the main window .
if i append to body of main page
<script type='text/javascript'><!--//<![CDATA[
var ox_u = 'http://ads.gamingxp.com/www/delivery/al.php?zoneid=224&cb=1333555766&layerstyle=simple&align=center&valign=middle&padding=2&closetime=200&padding=2&shifth=0&shiftv=0&closebutton=t&backcolor=FFFFFF&bordercolor=000000';
if (document.context) ox_u += '&context=' + escape(document.context);
document.write("<scr"+"ipt type='text/javascript' src='" + ox_u + "'></scr"+"ipt>");
//]]>--></script>
would it work?
here my first try, but seems no luck... I thhink I am escaping wrong way...
Could you hint out, pleaseee...
Paste from JSFIDDLE
Actually This is based on another code. And Jquery is not a must. I only need to paste the given ad code of OPEN X from within IFRAME to the parent's directory in some specific div by ID... Maybe you could hint out easyer workout? Problem is that the javascript given should run in Iframe ....
I assume you are saying that you want to access the parent window from within the iframe window. To do this, all you need to do is:
a. Make sure the parent window has the same "document.domain" as the child iframe, for example "domain.com"
b. You can dynamically add a variable to the parent document by simple doing:
window.top.myNewVariable = "yay";
In the above example, "myNewVariable" would be accessible from the parent document.
c. If you want to include an external script into the parent document, go ahead and create the script tag and append it to the parent document.
var myNewScript = document.createElement('script');
myNewScript.setAttribute('type','text/javascript');
myNewScript.src = "SOURCE OF SCRIPT";
window.top.document.getElementsByTagName("body")[0].appendChild(myNewScript);
Let me know if that works for you!