While working on a website, I have implemented an embed function which involves calling a javascript from my server to inject HTML on another remote server.
To ensure that these embeds also benefit from Google ranking, I have included a piece of HTML in the embed code. Here's how it looks:
<script type="text/javascript" src="http://myserver.com/myscript.js"></script>
<div id="embedSource">Source: <a href="myserver.com">mysite.com</a></div>
The issue arises when trying to detect the presence of the "embedSource" div within the embed code using a detection script in the initial "myscript.js". This is because the javascript is executed before the div is added to the DOM, making it impossible to add the embedSource div first.
I attempted to check this using:
window.onload = CheckIfEmbedCodeIsComplete();
However, this event is triggered too early in Chrome, FF and IE. Even though it should suffice for most browsers, right? I also tried:
setTimeOut(CheckIfEmbedCodeIsComplete(), 5000);
But once again, the check occurs immediately instead of after the specified 5 seconds.
What steps can I take to effectively verify the existence of that div?