objParen;
objTop += objParen;
objParent = objParen;
}
// 我们已经拿到了我们要定位的广告元素位置了
2 我们的广告
查看复制到剪切板打印
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/ JavaScript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="
</script>
</div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src=" /></script>
</div>
里面注意我使用了GOOGLE_COMMENT作为这个广告的ID,同时设置了CSS属性为绝对定位,不显示。
3 移动我们的广告到正确的位置
查看复制到剪切板打印
// 得到我们前面的广告对象
var gg = ("GOOGLE_COMMENT");
// 相对于我们要放广告的位置,加上一个偏移量
=(objLeft +450)+"px";
= (objTop+10)+"px";
// 显示广告
="";
// 得到我们前面的广告对象
var gg = ("GOOGLE_COMMENT");
// 相对于我们要放广告的位置,加上一个偏移量
=(objLeft +450)+"px";
= (objTop+10)+"px";
// 显示广告
="";
4 在页面装载完毕后再显示广告
因为我们的代码在整个页面的前部,所以不能一开始就运行,否则根本找不到一些在后面才出现的元素。
我们把自己的代码放在一个function里面
查看复制到剪切板打印
function GOOGLEResize(){
// 我们全部的初始化代码
}
// 当页面装载完毕后,再运行我们的程序
=GOOGLEResize;
function GOOGLEResize(){
// 我们全部的初始化代码
}
// 当页面装载完毕后,再运行我们的程序
=GOOGLEResize;
5 处理页面的resize事件
在IE里,可以简单的用
查看复制到剪切板打印
=GOOGLEResize;
=GOOGLEResize;
但是在Firefox里面,则必须用定时器进行定期检测才行
查看复制到剪切板打印
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
6 处理页面的异常
屏蔽掉可能出现的异常
查看复制到剪切板打印
function killErrors() {
return true;
}
= killErrors;
function killErrors() {
return true;
}
= killErrors;
至此,我所需要的代码已经全部完成了。
三、我的广告的完整代码
查看复制到剪切板打印
<script type="text/javascript">
function killErrors() {
return true;
}
= killErrors;
var init = false;
function GOOGLEResize(){
var subject = ("_ViewPost_PreviousAndNextEntriesUp");
if(!init){
=+"<br/><br/><br/><br/><br/><br/><hr/><br/>";
init = true;
}
var t = ("Anthem__PostComment_CommentUpdatePanel__");
var gg = ("GOOGLE_COMMENT");
objLeft = ;
objTop = ;
objParent = ;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
=(objLeft +450)+"px";
= (objTop+10)+"px";
="";
objLeft = subject .offsetLeft;
objTop = subject .offsetTop;
objParent = subject .offsetParent;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
var gg728=("GOOGLE_TOP");
= objLeft+"px";
= (objTop+50)+"px";
="";
}
=GOOGLEResize;
=GOOGLEResize;
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
</script>
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN摩天 160x600, 创建于 08-9-17 */
google_ad_slot = "5598761730";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="
</script>
<div id="GOOGLE_TOP" style="position:absolute;top:248px;left:250px;width:728;height:90;display:none"><scripttype="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN横幅 728x90, 创建于 08-9-17 */
google_ad_slot = "9488011826";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="
</script></div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="
</script>
</div>
<script type="text/javascript">
function killErrors() {
return true;
}
= killErrors;
var init = false;
function GOOGLEResize(){
var subject = ("_ViewPost_PreviousAndNextEntriesUp");
if(!init){
=+"<br/><br/><br/><br/><br/><br/><hr/><br/>";
init = true;
}
var t = ("Anthem__PostComment_CommentUpdatePanel__");
var gg = ("GOOGLE_COMMENT");
objLeft = ;
objTop = ;
objParent = ;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
=(objLeft +450)+"px";
= (objTop+10)+"px";
="";
objLeft = subject .offsetLeft;
objTop = subject .offsetTop;
objParent = subject .offsetParent;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
var gg728=("GOOGLE_TOP");
= objLeft+"px";
= (objTop+50)+"px";
="";
}
=GOOGLEResize;
=GOOGLEResize;
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
</script>
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN摩天 160x600, 创建于 08-9-17 */
google_ad_slot = "5598761730";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src=" /></script>
<div id="GOOGLE_TOP" style="position:absolute;top:248px;left:250px;width:728;height:90;display:none"><scripttype="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN横幅 728x90, 创建于 08-9-17 */
google_ad_slot = "9488011826";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src=" /></script></div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src=" /></script>
</div>
objTop += objParen;
objParent = objParen;
}
// 我们已经拿到了我们要定位的广告元素位置了
2 我们的广告
查看复制到剪切板打印
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/ JavaScript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="
</script>
</div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src=" /></script>
</div>
里面注意我使用了GOOGLE_COMMENT作为这个广告的ID,同时设置了CSS属性为绝对定位,不显示。
3 移动我们的广告到正确的位置
查看复制到剪切板打印
// 得到我们前面的广告对象
var gg = ("GOOGLE_COMMENT");
// 相对于我们要放广告的位置,加上一个偏移量
=(objLeft +450)+"px";
= (objTop+10)+"px";
// 显示广告
="";
// 得到我们前面的广告对象
var gg = ("GOOGLE_COMMENT");
// 相对于我们要放广告的位置,加上一个偏移量
=(objLeft +450)+"px";
= (objTop+10)+"px";
// 显示广告
="";
4 在页面装载完毕后再显示广告
因为我们的代码在整个页面的前部,所以不能一开始就运行,否则根本找不到一些在后面才出现的元素。
我们把自己的代码放在一个function里面
查看复制到剪切板打印
function GOOGLEResize(){
// 我们全部的初始化代码
}
// 当页面装载完毕后,再运行我们的程序
=GOOGLEResize;
function GOOGLEResize(){
// 我们全部的初始化代码
}
// 当页面装载完毕后,再运行我们的程序
=GOOGLEResize;
5 处理页面的resize事件
在IE里,可以简单的用
查看复制到剪切板打印
=GOOGLEResize;
=GOOGLEResize;
但是在Firefox里面,则必须用定时器进行定期检测才行
查看复制到剪切板打印
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
6 处理页面的异常
屏蔽掉可能出现的异常
查看复制到剪切板打印
function killErrors() {
return true;
}
= killErrors;
function killErrors() {
return true;
}
= killErrors;
至此,我所需要的代码已经全部完成了。
三、我的广告的完整代码
查看复制到剪切板打印
<script type="text/javascript">
function killErrors() {
return true;
}
= killErrors;
var init = false;
function GOOGLEResize(){
var subject = ("_ViewPost_PreviousAndNextEntriesUp");
if(!init){
=+"<br/><br/><br/><br/><br/><br/><hr/><br/>";
init = true;
}
var t = ("Anthem__PostComment_CommentUpdatePanel__");
var gg = ("GOOGLE_COMMENT");
objLeft = ;
objTop = ;
objParent = ;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
=(objLeft +450)+"px";
= (objTop+10)+"px";
="";
objLeft = subject .offsetLeft;
objTop = subject .offsetTop;
objParent = subject .offsetParent;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
var gg728=("GOOGLE_TOP");
= objLeft+"px";
= (objTop+50)+"px";
="";
}
=GOOGLEResize;
=GOOGLEResize;
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
</script>
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN摩天 160x600, 创建于 08-9-17 */
google_ad_slot = "5598761730";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="
</script>
<div id="GOOGLE_TOP" style="position:absolute;top:248px;left:250px;width:728;height:90;display:none"><scripttype="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN横幅 728x90, 创建于 08-9-17 */
google_ad_slot = "9488011826";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="
</script></div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="
</script>
</div>
<script type="text/javascript">
function killErrors() {
return true;
}
= killErrors;
var init = false;
function GOOGLEResize(){
var subject = ("_ViewPost_PreviousAndNextEntriesUp");
if(!init){
=+"<br/><br/><br/><br/><br/><br/><hr/><br/>";
init = true;
}
var t = ("Anthem__PostComment_CommentUpdatePanel__");
var gg = ("GOOGLE_COMMENT");
objLeft = ;
objTop = ;
objParent = ;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
=(objLeft +450)+"px";
= (objTop+10)+"px";
="";
objLeft = subject .offsetLeft;
objTop = subject .offsetTop;
objParent = subject .offsetParent;
while( () != "BODY" )
{
objLeft += objParen;
objTop += objParen;
objParent = objParen;
}
var gg728=("GOOGLE_TOP");
= objLeft+"px";
= (objTop+50)+"px";
="";
}
=GOOGLEResize;
=GOOGLEResize;
var startWidth = ("body")[0].offsetWidth;
function checkFFresize() {
var resizeWidth = ("body")[0].offsetWidth;
if (resizeWidth == startWidth) {
} else {
startWidth=("body")[0].offsetWidth;
GOOGLEResize();
}
setTimeout("checkFFresize();",2000);
}
if () {
} else {
setTimeout("checkFFresize();",1000);
}
</script>
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN摩天 160x600, 创建于 08-9-17 */
google_ad_slot = "5598761730";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src=" /></script>
<div id="GOOGLE_TOP" style="position:absolute;top:248px;left:250px;width:728;height:90;display:none"><scripttype="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* CSDN横幅 728x90, 创建于 08-9-17 */
google_ad_slot = "9488011826";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src=" /></script></div>
<div id="GOOGLE_COMMENT" style="position:absolute;display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-2908059660288034";
/* 300x250, 创建于 08-9-16 */
google_ad_slot = "0023597101";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src=" /></script>
</div>