页面加载后不允许document.write? [英] Not allowed document.write after page load?

查看:214
本文介绍了页面加载后不允许document.write?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被告知在页面加载后你不能使用document.write,这是真的吗?

I've been told that you can't use document.write after a page load, is this true?

我创建了一个非常简单的Javascript文件包含在用作广告脚本的网站中。它只包含一个 document.write('Link Here')。我被告知我不应该这样做虽然显然它不正确,它会阻止页面加载吗?

I've created an extremely simple Javascript file that gets included from websites which serves as an advertising script. It just includes a document.write('Link Here'). I've been told that I should not do this though as apparently it isn't correct, and it will stop the page from loading?

这是真的吗?它适用于我。

Is this true? It works fine for me.

谢谢

推荐答案

如果你只是写入文档本身它将删除页面内容,您将只留下新文本。

If you just write to the document itself it'll remove the page content and you'll be left with only the new text.

尝试使用:

document.getElementById('DIVID').innerHTML = "YOUR HTML HERE"

将DIVID替换为包含广告的元素,并将您的HTML HERE替换为您要写入页面的任何内容。这样您还可以更轻松地在网页上定位广告。

Substitute 'DIVID' for the element that will contain the ad and 'YOUR HTML HERE' for whatever you want to be written to the page). This will also allow you to position the ad on the page more easily.

这篇关于页面加载后不允许document.write?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆