When i paste this code to begining
Your script appears before the <embed>
element.
Your script, therefore, runs before the <embed>
element is added to the DOM.
The <embed>
element, therefore, does not exist when you try to modify it.
So don't do that.
when paste to end, its work fine, but the content is already loaded and the script not affect the operation
If modifying the element after it exists doesn't work either, then create the entire element using JavaScript.
var myEmbed = document.createElement("embed");
myEmbed.setAttribute("src", source);
document.body.appendChild(myEmbed);