JS, showModalDialog problem.
I have the following JS:
Code:
function openSelectVisitor(iBookingKey)
{
var sFeatures = ''
sFeatures=''
sFeatures+='top=100,'
sFeatures+='left=200,'
sFeatures+='height=500px,'
sFeatures+='width=400px,'
sFeatures+='scrollbars=no,status=no,toolbar=no'
window.showModalDialog('SelectVisitor.aspx?BookingKey='+iBookingKey,'SelectVisitor',sFeatures)
}
This works fine, and my popup window is shown.
In this popup I have a close button, and in page load I do:
VB Code:
btnClose.Attributes.Add("onClick", "javascript:window.close();")
Now when I click this close button the page does indeed close...but for some strange reason, another instance of this is opened, which is NOT a Modal Dialog, but instead a modeless popup...plus this time the address bar is visible.
I have put a break point on the Page_Load event of the popup, and sure enough, when I click the close button, the Page_Load event gets fired again.
I have absolutely no other code in the popup except the btnClose.Attributes bit.
If I change my main calling JS function so it shows the Popup and modeless:
Code:
window.Open('SelectVisitor.aspx?BookingKey='+iBookingKey,'SelectVisitor',sFeatures)
Then I do not have this problem and the popup closes fine when close.
Any ideas?
Woka
Re: JS, showModalDialog problem.
I think you need to change this:
Code:
btnClose.Attributes.Add("onClick", "javascript:window.close();")
To this:
Code:
btnClose.Attributes.Add("onClick", "window.close();")
Re: JS, showModalDialog problem.
Got it:
The button was causing the popup to submit, to stop this I added Return False to the JS:
VB Code:
btnClose.Attributes.Add("onClick", "javascript:window.close();return false;")
Woka
Re: JS, showModalDialog problem.
Yuo forgot to mention that it was a submit button. ;)
If it never submits then it is best to use a <button>Button Text</button> tage.