Why so you need to use JS to create that <object>...</object> code? Why can't you just drop it in the HTML without using JS at all?
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.