小弟动态生成了一个iframe,但往里面写html内容时,网页报错,说“没有权限”,页面也不显示部分代码如下: <script type="text/javascript">
window.onload=init;
function init()
{
var queryinfo=document.getElementById("queryinfo");
// alert(queryinfo.name);
var mt_iframe = document.createElement("mt_iframe");
mt_iframe.id="mt_iframe";
mt_iframe.src="about:blank";
queryinfo.appendChild(mt_iframe);
var pname_iframe = document.createElement("pname_iframe");
pname_iframe.id="pname_iframe";
pname_iframe.src="about:blank";
queryinfo.appendChild(pname_iframe);
var ppart_iframe = document.createElement("ppart_iframe");
ppart_iframe.id="ppart_iframe";
ppart_iframe.src="about:blank";
queryinfo.appendChild(ppart_iframe);
var dp_iframe = document.createElement("dp_iframe");
dp_iframe.id="dp_iframe";
dp_iframe.src="about:blank";
queryinfo.appendChild(dp_iframe);
var cu_iframe = document.createElement("cu_iframe");
cu_iframe.id="cu_iframe";
cu_iframe.src="about:blank";
queryinfo.appendChild(cu_iframe);
var phase_iframe = document.createElement("phase_iframe");
phase_iframe.id="phase_iframe";
phase_iframe.src="about:blank";
queryinfo.appendChild(phase_iframe); //任务书类型
var doc=window.frames["mt_iframe"].document;
// alert(doc);
var html="";
<%
for(int i=0;i<mtVector.size();i++)
{
MissionType mt=(MissionType)mtVector.get(i);
%>
html+='<input type="checkbox" name="missiontypes" value="<%=mt.getMtId()%>"/><%=mt.getMtName()%><br/>\n';
<%
}
%>
alert(html);
doc.open();
// alert("eee");
doc.write(html);
doc.close();我测试过了 出问题的就在doc.write(html)和doc.close()那里~
queryinfo是一个div层~
请各位高手赐教,点出问题所在,谢谢
window.onload=init;
function init()
{
var queryinfo=document.getElementById("queryinfo");
// alert(queryinfo.name);
var mt_iframe = document.createElement("mt_iframe");
mt_iframe.id="mt_iframe";
mt_iframe.src="about:blank";
queryinfo.appendChild(mt_iframe);
var pname_iframe = document.createElement("pname_iframe");
pname_iframe.id="pname_iframe";
pname_iframe.src="about:blank";
queryinfo.appendChild(pname_iframe);
var ppart_iframe = document.createElement("ppart_iframe");
ppart_iframe.id="ppart_iframe";
ppart_iframe.src="about:blank";
queryinfo.appendChild(ppart_iframe);
var dp_iframe = document.createElement("dp_iframe");
dp_iframe.id="dp_iframe";
dp_iframe.src="about:blank";
queryinfo.appendChild(dp_iframe);
var cu_iframe = document.createElement("cu_iframe");
cu_iframe.id="cu_iframe";
cu_iframe.src="about:blank";
queryinfo.appendChild(cu_iframe);
var phase_iframe = document.createElement("phase_iframe");
phase_iframe.id="phase_iframe";
phase_iframe.src="about:blank";
queryinfo.appendChild(phase_iframe); //任务书类型
var doc=window.frames["mt_iframe"].document;
// alert(doc);
var html="";
<%
for(int i=0;i<mtVector.size();i++)
{
MissionType mt=(MissionType)mtVector.get(i);
%>
html+='<input type="checkbox" name="missiontypes" value="<%=mt.getMtId()%>"/><%=mt.getMtName()%><br/>\n';
<%
}
%>
alert(html);
doc.open();
// alert("eee");
doc.write(html);
doc.close();我测试过了 出问题的就在doc.write(html)和doc.close()那里~
queryinfo是一个div层~
请各位高手赐教,点出问题所在,谢谢
<div id="odiv"></div>
<script type="text/javascript">
<!--
window.onload = function(){
var oframe = document.createElement("iframe");
oframe.id="oframe";
oframe.src="about:blank";
document.getElementById("odiv").appendChild(oframe);
var doc = document.getElementById("oframe").contentWindow.document || document.getElementById("oframe").contentDocument;
doc.write("test");
doc.close();
}
//-->
</script>给你个实例参考下
<script language="javascript"> window.onload=function(){
var queryinfo=document.getElementById("queryinfo");
var mt_iframe = document.createElement("iframe");
mt_iframe.id="mt_iframe";
mt_iframe.src="about:blank";
queryinfo.appendChild(mt_iframe);
var doc=window.frames["mt_iframe"].document;
doc.open();
doc.write("<input type=\"checkbox\" name=\"missiontypes\" value=\"x\"/>");
doc.close();
}
</script>
<div id="queryinfo" ></div>
楼上hookee兄这样应该不兼容FF.应该再加个mt_iframe.name="mt_iframe";才可以吧