My problem was that I wanted to add JavaScript into a html page, thanks to Andy E, I find the way to add my JavaScript into a html page and be executed. But now my problem is that all the page is overwritten by the JavaScript. Someone know how to do the same thing but without overwritten the page with the JavaScript, something to add to the code or something to change :) ?
- I don't want to reload the page because I don't want that the user see the page twice, if the page contain a lot of stuff it will be very inconvenient.
This is a short-code which show you my problem: (I changed the ad tag because it is not mine, so I can not put it in this public place)
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {;
var correct_div = document.getElementById('ad_468x60');
var sTag1 = document.createElement("script");
sTag1.type = "text/javascript";
sTag1.text = "<!--\ngoogle_ad_client = \"pub-1234567890123456\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 468;\ngoogle_ad_height = 60;\ngoogle_ad_format = \"468x60_as\";\ngoogle_ad_channel =\"123456789\";\ngoogle_color_border = \"FFFFC6\";\ngoogle_color_bg = \"FFFFFF\";\ngoogle_color_link = \"000000\";\ngoogle_color_url = \"666666\";\ngoogle_color_text = \"333333\";\n//-->"
correct_div.appendChild(sTag1);
var sTag2 = document.createElement("script");
sTag2.type = "text/javascript";
sTag2.src = "http://google_ad_url.js";
correct_div.appendChild(sTag2)
});
</script>
</head>
<body>
<div>
"This text appears and disappears after the ad is displayed"
</div>
<div id="ad_468x60">
<!-- The JavaScript come here -->
</div>
</body>
</html>
EDIT : Could I use an iframe to do this ?