-1

I'm calling this function:

<script type='text/javascript'><!--// <![CDATA[
    OA_show(18);
// ]]> --></script>

at many sites on a page but the script is loaded at bottom as follow:

<script type='text/javascript' src='//openx.elclarinweb.com/www/delivery/spcjs.php?id=2&#038;target=_blank&#038;ver=20141010'></script>

which causes this error:

Uncaught ReferenceError: OA_show is not defined

Note

I can't call the function after script loads because it needs to be called on specific position where Ads will be show, take a look here to see what I'm talking about

Is there any way to get ride of the error? Should I load the script at top even if it's obtrusive and prevent the page to load before it loads completely? Any advice?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363

2 Answers2

4

put in onload:

window.onload = function(){
   OA_show(18);
};

This waits for all the resources to be loaded and then executes the function you are calling.

Jai
  • 74,255
  • 12
  • 74
  • 103
  • Hi @Jai, this is not working the `OA_show()` function display some image from OpenX server but put in the way you said redirect me to the image – ReynierPM Feb 20 '15 at 00:02
1

Just call the function at bottom after the script loads.

...
</body>
<script type='text/javascript' src='//openx.elclarinweb.com/www/delivery/spcjs.php?id=2&#038;target=_blank&#038;ver=20141010'></script>

<script type='text/javascript'><!--// <![CDATA[
    OA_show(18);
</script>

EDIT

Then do window.onload = OA_show(18);

void
  • 36,090
  • 8
  • 62
  • 107