Organizing multiple embed codes with jQuery

I have several embed codes on my website, for example:

Insert code # 1:

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/f8Lp2ssd5A9ErAc&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/f8Lp2A9ErAc&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

Insert code # 2:

<script type="text/javascript">
_qoptions={
qacct:"p-3asdb5E0g6"
};
</script>
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<noscript>
<a href="http://www.quantcast.com/p-3asdb5E0g6" target="_blank"><img src="http://pixel.quantserve.com/pixel/p-3asdb5E0g6.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/></a>
</noscript>

etc.

How to organize them and split them into an external js file to save markup?

Thank you for your help!

+3
source share
1 answer

I don’t see jQuery help a lot. I would either document.write them directly, or maybe save them in an XML file

With document.write, it will be something like this (where noscript is removed, since there is no point in having it in the js file

// --- starts jsfile
var embeds = [
'<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/f8Lp2ssd5A9ErAc&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/f8Lp2A9ErAc&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>',

'<script type="text/javascript">_qoptions={qacct:"p-3asdb5E0g6"};</script><script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>'
]; // notice the lack of comma on the last embed
function putEmbed(idx) {
  document.write(embeds[idx]);
}
// ------ end ------

and then use

<script type="text/javascript">
putEmbed(0); // youtube
</script>

and later

<script type="text/javascript">
putEmbed(1); // quant
</script>
+2
source

Source: https://habr.com/ru/post/1742761/


All Articles