admin管理员组文章数量:1356908
After clicking close button
current window is not closing in Firefox
but its working fine in IE
function closeWin() {
var d=window.opener;
try {
var param="";
var winHref=d.document.location.href;
if(winHref.indexOf("?") > -1){
param=winHref.substr(winHref.indexOf("?"));
}
//d.document.location.href=d.document.forms[0].thankyouurl.value+'?'+param;
d.document.location.href=d.document.getElementsByName('thankyouurl')[0].value+'?'+param;
}
catch(e){}
finally{}
window.close();
return true;
}
<input type="button" name="Button" value="Close" onClick="return closeWin();">
After clicking close button
current window is not closing in Firefox
but its working fine in IE
function closeWin() {
var d=window.opener;
try {
var param="";
var winHref=d.document.location.href;
if(winHref.indexOf("?") > -1){
param=winHref.substr(winHref.indexOf("?"));
}
//d.document.location.href=d.document.forms[0].thankyouurl.value+'?'+param;
d.document.location.href=d.document.getElementsByName('thankyouurl')[0].value+'?'+param;
}
catch(e){}
finally{}
window.close();
return true;
}
<input type="button" name="Button" value="Close" onClick="return closeWin();">
Share
Improve this question
edited Aug 13, 2015 at 7:49
Vivek Jain
3,8856 gold badges32 silver badges47 bronze badges
asked Aug 13, 2015 at 7:17
manikandan Smanikandan S
531 gold badge1 silver badge6 bronze badges
2
-
what error are you getting in the console - I'm guessing
Scripts may not close windows that were not opened by script.
– Jaromanda X Commented Aug 13, 2015 at 7:17 - possible duplicate of window.close(), self.close() not working on mozilla firefox – Madness Commented Aug 13, 2015 at 7:20
1 Answer
Reset to default 5You can't close the page with window.close() in Firefox unless it is opened by a script. So you'll have to trick Firefox in thinking you opened it with a script. This would work:
function closeWindow() {
window.open('','_parent','');
window.close();
}
Now just call the closeWindow() whenever you want the window to close. This works in other browsers too.
本文标签: javascriptwindowclose() not working in firefoxStack Overflow
版权声明:本文标题:javascript - window.close(); not working in firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744057725a2583557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论