0

我是一个 JS 菜鸟,所以如果这个问题太“菜鸟”,请原谅。

注意:函数很长,但只需向下滚动直到看到 // * ** * ** * **因为这是重要的部分。

我的功能:

function ShowWindowN(userId,url,width,height,courseId) {
  var iev=getIEVer();
  if(iev>=6&&iev<8){
    width+=16*1;
  }
  var w=screen.availWidth<width?screen.availWidth:width;
  var csCookie=readCookie('course_settings_'+userId);
  var found=false;
  if(csCookie!=null){
    csCookie=eval('({'+csCookie.replace(/&/g,',').replace(/=/g,':')+'})');
    if(csCookie[courseId]!=null){
      height+=1*csCookie[courseId].height;
      found=true;
    }
  }
  if(!found){
    var plCookie=readCookie('player_settings_'+userId);
    if(plCookie!=null){
      plCookie=eval('({'+plCookie.replace(/&/g,',').replace(/=/g,':')+'})');
      height+=1*plCookie.window_extra_height;
    }else{
      height+=16;
    }
  }
  var h=screen.availHeight<height?screen.availHeight:height;
  var left = (screen.availWidth/2)-(w/2);
  //************
  objMovieWindow=window.open(url, "movieWindow", "width=" + w + ", height=" + h + ", top=0, left="+left+", status=false, toolbar=false, menubar=false, location=false, directories=false, scrollbars=1, resizable=1"); 
  objMovieWindow.focus();
  //alert(objMovieWindow.name);
};

如果您查看最后一行第二行的 alert() ,它不起作用,它会给我一个“权限被拒绝”错误。我也有一个函数,上面写着“close_me()”:

objMovieWindow.close();

但这不起作用,并给我一个“未定义”的错误。基本上,我加载页面,然后单击链接以启动弹出窗口,然后重新加载父页面,并通过单击父页面上的链接来关闭弹出窗口。

请告诉我如何关闭该死的弹出窗口?

4

1 回答 1

2

When you reload the page you are losing the reference to objMovieWindow, so you won't be able to call objMovieWindow.close(). You'll have to avoid reloading the page if you want to close the window.

UPDATE

One work around would be to call window.open() again with the same name, and call close() on the reference returned from that.

于 2012-11-18T04:23:51.410 回答