简体   繁体   English

Javascript:关闭弹出窗口

[英]Javascript: closing a popup window

I am a JS noob, so please excuse me if this question is too "noobish". 我是一个JS菜鸟,所以如果这个问题太“无趣”,请原谅。

Note: the function is long, but just scroll down till you see // * ** * ** * ** as that's the important part. 注意:函数很长,但只需向下滚动直到看到// * ** * ** * **,因为这是重要的部分。

My function: 我的功能:

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

If you look at the alert() on the 2nd last line, that does not work, it gives me a "permissions denied" error. 如果你查看最后一行的alert(),这不起作用,它会给我一个“权限被拒绝”的错误。 I also have a function that says "close_me()" with just this: 我还有一个函数,用这句话说“close_me()”:

objMovieWindow.close();

But that does not work and gives me an "undefined" error. 但这不起作用,并给我一个“未定义”的错误。 Basically, I load the page, and click a link to launch the popup, then the parent page reloads, and by clicking a link on the parent page I want to close the popup. 基本上,我加载页面,然后单击链接以启动弹出窗口,然后重新加载父页面,并通过单击父页面上的链接我要关闭弹出窗口。

Please tell me how I can close the damn popup window? 请告诉我如何关闭该死的弹出窗口?

When you reload the page you are losing the reference to objMovieWindow , so you won't be able to call objMovieWindow.close() . 当您重新加载页面时,您将丢失对objMovieWindow的引用,因此您将无法调用objMovieWindow.close() You'll have to avoid reloading the page if you want to close the window. 如果要关闭窗口,则必须避免重新加载页面。

UPDATE UPDATE

One work around would be to call window.open() again with the same name, and call close() on the reference returned from that. 一个解决方法是再次使用相同的名称调用window.open() ,并从返回的引用上调用close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM