Javascript 打开iframe src到新页面
我的网页首先打开app.html。单击登录后,我需要打开index.html,我在iframe中打开它,并在javascript中动态创建iframe。因此,要打开该框架,我会将其附加到document.body。但它会附加到app.html的主体。但我需要在新页面中打开Javascript 打开iframe src到新页面,javascript,html,iframe,Javascript,Html,Iframe,我的网页首先打开app.html。单击登录后,我需要打开index.html,我在iframe中打开它,并在javascript中动态创建iframe。因此,要打开该框架,我会将其附加到document.body。但它会附加到app.html的主体。但我需要在新页面中打开 var el = document.createElement("iframe"); el.setAttribute('id', 'ifrm'); el.setAttribute('name', 'ifrm'); el.set
var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
el.setAttribute('name', 'ifrm');
el.setAttribute('src', '/index/index.html');
el.setAttribute('width', '100%');
el.setAttribute('height', '100%');
el.setAttribute('scrolling', 'no');
document.body.appendChild(el);
您可以使用此选项在新窗口中打开:
var myWindow = window.open("/index/index.html");
您必须在当前页面上分层iframe el.style.position='绝对'; el.style.top=0;
el.style.left=0 你的问题有点不清楚你想做什么。答案取决于以下因素:
index.html
添加到app.html
还是代替它
JavaScript弹出窗口示例
函数loginCheck(){
//isLoggedIn是一个设置为检查登录名的布尔变量
如果(isLoggedIn){
弹出();
}
}
函数popon(){
var-winOptions=“”;
winOptions+=“位置=1”;
winOptions+=“状态=0”;
winOptions+=“滚动条=0”;
winOptions+=“宽度=100”;
winOptions+=“高度=100”;
newWin=window.open(
“index.html”,
“我的应用程序的主窗口”,
winOptions
);
newWin.moveTo(400300);//向下300像素,
//右边400像素
}
JavaScript弹出窗口示例
index.html
?
只需在锚定标记中使用
target
属性,将值设置为new
,例如您的问题有点令人困惑。。。您是否尝试在原始app.html之外打开index.html N,作为弹出窗口、新选项卡或在同一窗口/选项卡/框架中打开,换句话说,是要替换它?请提供更多信息,我们可以更好地帮助您。
<html>
<head>
<title>JavaScript Popup Example</title>
<script type="text/javascript">
function loginCheck(){
//isLoggedIn is a boolean variable you've set to check login
if (isLoggedIn) {
popup();
}
}
function popon(){
var winOptions = "";
winOptions += "location=1, ";
winOptions += "status=0, ";
winOptions += "scrollbars=0, ";
winOptions += "width=100, ";
winOptions += "height=100";
newWin = window.open(
"index.html",
"My App's Main Window",
winOptions
);
newWin.moveTo(400, 300); //300 pixels down,
//400 pixels to the right
}
</script>
</head>
<body onload="javascript: loginCheck()">
<h1>JavaScript Popup Example</h1>
</body>
</html>