Window.open在iframe的想法

时间:2012-09-26 13:07:45

标签: javascript html

我不确定是否可以这样做。我在我看来有这个代码:

  <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();
}

当我点击发布时,它会调用:

  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();
      } 

然后我在我看来iframe:

  <iframe id="iframe" class="targetblank"></iframe>

它也永远不会到达setWindowSize中的警报:( document.getElementById("iframe").addEventListener('resize', function ()行无效。

0 个答案:

没有答案