0

I Want to Close window.dialog. I open window as below,

window.$('<div align="center" style="width:100%;height:100%;"><iframe src="'+fdt+'" width="100%" height="100%" frameborder="0" scrolling="no"></iframe></div>').dialog({ 
     modal: true,
     width: 460, 
     height: 450,
     title: "Serial"
    });

After open dialog, when press enter key on input I want to close this window. Please Help me.

$(document).ready(function(){
$('#stsr').keypress(function(e) {
    if(e.keyCode==13){
          //I Want to close this window
    }
});
});
Jenz
  • 8,280
  • 7
  • 44
  • 77
UW Madhu
  • 3
  • 1

2 Answers2

1

Give the DIV an ID

window.$('<div id="dialog" align="center" style="width:100%;height:100%;"><iframe src="'+fdt+'" width="100%" height="100%" frameborder="0" scrolling="no"></iframe></div>').dialog({ 
     modal: true,
     width: 460, 
     height: 450,
     title: "Serial"
});

Then you can refer to it later:

$(document).ready(function(){
    $('#stsr').keypress(function(e) {
        if(e.keyCode==13){
            $("#dialog", window.parent.document).dialog("close");
        }
    });
});
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Is the keypress code running inside the iframe? I assumed it was running in the parent document. – Barmar Aug 21 '14 at 06:20
  • I've updated the answer to access the parent document. This will only work if they're in the same domain. – Barmar Aug 21 '14 at 06:47
0

Probably the same question here. window.close() should do the trick:

if(e.keyCode==13){
      close();
}
Community
  • 1
  • 1
2ooom
  • 1,760
  • 1
  • 23
  • 37