Can I set how long a popup window has focus?
I have a side navigation bar and when you click the links it submits a form. The forms action opens another page ( target _blank). My problem is I have to open a popup window before this blank page opens and keep it open long enough for the user to read it or atleast see it first and close it if they wish. I created a function that opens the popup on the onclick event of the link. Looks like this:
<li><a href="JavaScript:document.quoteform.submit()" o开发者_如何学Pythonnclick="popUp('ag_popup.html')">Submit a Deal</a></li>
and my function looks like this:
function popUp(url)
{
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - 150
topPos = (screen.height / 2) - 250
}
newwindow=window.open(url,'name','height=300,width=500,left='+leftPos+',top='+topPos);
if (window.focus) {newwindow.focus()}
return false;}
Does anyone know if I can just keep my popup open and focused without my new blank page opening up infront of it?
Cheers
You could use the setTimeout-Function to wait, hold the reference on the popup and close it then(or let the user decide!). After that submit the form from that function.
For example:
var newWindow=null;
function popUp(url)
{
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - 150
topPos = (screen.height / 2) - 250
}
newWindow=window.open(url,'name','height=300,width=500,left='+leftPos+',top='+topPos);
if (window.focus) {newWindow.focus()}
setTimeout('closePopupAndSubmit()')', 5000);
}
function closePopupAndSubmit{
if(newWindow != null){
newWindow.close();
document.quoteform.submit();
}
}
精彩评论