简体   繁体   中英

BASH CGI script - how to close web page

I apologise if this question seems silly.

I have a BASH script stored in the cgi-bin directory. The script is called through a browser window. A couple of query_string arguments are included in the URL, and the script outputs a .html file. It all works as it should. Is there a way to close the browser window once the script has finished running? Does the script even need the browser to remain open for the whold period it is running?

Using unix/Apache/Samba. The web instance is launched from Windows 7.

Thanks.

So I solved this issue with a simple redirection of stdout once my html output file was built, and some basic html to close the browser window.

exec 3>&1 4>&2
exec > output.html

echo "my html stuff"

exec >&3 2>&4

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Close browser</title>"
echo "<script type='text/javascript'>"
echo "window.open('', '_self', ''); window.close();"
echo "</script></head><body>"
echo "</body></html"

She may not be the prettiest, but it works a treat. Note that this solution is IE specific, in so far as the window closing line is a hack to avoid the security popup that a script is trying to close the page. I only need this to work in IE for the moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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