Javascript 窗口。在iframe中打开
我不确定这是否可以做到。我认为有以下代码:Javascript 窗口。在iframe中打开,javascript,html,Javascript,Html,我不确定这是否可以做到。我认为有以下代码: <div class="col3"> <a id="training-launch-button" href='javascript:OpenScormModuleWindow(<%: Model.ScormModuleId %> , "<%: ViewBag.ScormModuleUrl %>", "<%: ViewBag.title %>", <%: ViewBag.Win
<div class="col3">
<a id="training-launch-button" href='javascript:OpenScormModuleWindow(<%: Model.ScormModuleId %> , "<%: ViewBag.ScormModuleUrl %>", "<%: ViewBag.title %>", <%: ViewBag.WindowWidth %>, <%: ViewBag.WindowHeight %>);' class="button" onclick ="Test()">Launch</a>
</div>
function OpenScormModuleWindow(scormModuleId, scormModuleUrl, title, width, height) {
_scormModuleId = scormModuleId;
InitializeUserScormModule();
scormModuleWindow = window.open(scormModuleUrl, "title", "width=" + width + ", height=" + height + ", resizable = 1");
scormModuleWindow.focus();
}
函数openScormModule窗口(ScormModule ID、ScormModule URL、标题、宽度、高度){
_scormModuleId=scormModuleId;
初始化UserScormModule();
SCOMModuleWindow=window.open(SCOMModuleURL,“标题”,“宽度=“+width+”,高度=“+height+”,可调整大小=1”);
scormModuleWindow.focus();
}
当我点击launch时,它会调用:
function Test() {
alert("try launch in new window");
var newwindow = document.getElementsByClassName('targetblank');
newwindow.target = '_blank';
document.getElementById("iframe").src = "<%: ViewBag.ScormModuleUrl %>";
document.getElementById("iframe").addEventListener('resize', function () {
setWindowSize();
});
}
function setWindowSize() {
alert("in set winodw size");
var myWidth = 0, myHeight = 0;
if (typeof (window.outerWidth) == 'number')
{
myWidth = window.outerWidth;
myHeight = window.outerHeight;
alert(window.innerWidth + " 1 " + window.innerHeight + " " + document.documentElement.clientWidth + " " + document.documentElement.clientHeight);
alert(myHeight + " " + myWidth);
$("#LaunchWidth").val(document.documentElement.clientWidth);
$("#LaunchHeight").val(document.documentElement.clientHeight);
updateSaveButtons();
}
功能测试(){
警报(“在新窗口中尝试启动”);
var newwindow=document.getElementsByClassName('targetblank');
newwindow.target=''u blank';
document.getElementById(“iframe”).src=“”;
document.getElementById(“iframe”).addEventListener('resize',function(){
setWindowsSize();
});
}
函数setWindowsSize(){
警报(“设置中的winodw大小”);
var myWidth=0,myHeight=0;
if(typeof(window.outerWidth)=‘number’)
{
myWidth=window.outerWidth;
myHeight=window.outerHeight;
警报(window.innerWidth+“1”+window.innerHeight+“”+document.documentElement.clientWidth+“”+document.documentElement.clientHeight);
警报(myHeight+“”+myWidth);
$(“#LaunchWidth”).val(document.documentElement.clientWidth);
$(“#LaunchHeight”).val(document.documentElement.clientHeight);
updateSaveButtons();
}
在我看来,iframe:
<iframe id="iframe" class="targetblank"></iframe>
它也永远不会到达SetWindowsSize中的警报:(
行
document.getElementById(“iframe”).addEventListener('resize',function()
不起作用。如果您想在一个框架中打开url,您只需创建或获取一个iframe,然后将iframe的src设置为要传递给window.open的url。请参阅OP.。我现在有了,但不确定它是否正确,谢谢。我想我不确定您的目标。您想在一个可调整大小的窗口中打开url吗?您想要一个偶数吗当窗口调整大小时,为什么需要在iframe中使用它?我认为您需要添加更多的上下文,可能还需要添加一些您试图实现的内容。