ryanve / response.js

Responsive design toolkit
http://responsejs.com
Other
801 stars 123 forks source link

Script element integration #42

Closed clement-bongibault closed 10 years ago

clement-bongibault commented 10 years ago

Hello,

I'm trying to use responseJS to integrete advertising script like :

<div 
data-min-width-980='<script language="text/javascript">var my_config_var={play_button:1,show_status:0};</script><script language="text/javascript" src="http://www.example.com/partner.js"></script>'
>
</div>

First Inline script seems to work, but distant javascript call isn't work.

Is-it a bug, or something that else ?

Thanks for your replies.

ryanve commented 10 years ago

We use .innerHTML and HTML5 specifies that a <script> tag inserted via innerHTML should not execute. Find a better way—perhaps with an async script loader. I'd probably base it on device width. In any case you want to avoid repeating the execution when someone resizes the viewport. Only run it once.

<script>
window.my_config_var = {play_button:1, show_status:0};
if (Response.deviceW() >= 980) jQuery.getScript('http://www.example.com/partner.js');
</script>