Bashabi
Bashabi

Reputation: 706

Script for a close button which will work both for colorbox popup and normal popup in a asp.net and vb.net application

I have a page which opens as a popup from two different area. In the first area it opens as a colorbox popup. And from the second one it opens inside another simple javascript popup.

The page was previously designed as a colorbox popup. And the close button designed for the page works only when it opens as colorbox popup.

        <a href="javascript:parent.$.colorbox.close();" class="btn" title="Close Window">Cancel</a>

Problem is the close button does not work when it opens inside another simple popup. I normally use the following line of code for the close button of normal simple popup.

           <a class="btn" href="javascript:window.close();">Close</a>

That works when the page opens inside anohter normal javascript popup but that doesnot work when the popup opens as a colorbox popup.

Is there any script that will work in both cases?

I have tried to close the popup window via vb.net by using the following code .

asp.net line of code

<asp:LinkButton runat="server" EnableViewState="false" ID="uxClose"
        Text="Close Window via Asp" CssClass="btn" />

VB.net code

Protected Sub uxClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxClose.Click
    If Not Page.IsValid Then Exit Sub
    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CloseWindowScript", "window.close();", True)

   End Sub

that does not work.I have also tried

 Protected Sub uxClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxClose.Click
    If Not Page.IsValid Then Exit Sub
   Me.close()
 End Sub

but that gives error message

I will appreciate your kind co operation

Thank you

Upvotes: 0

Views: 366

Answers (1)

foxygen
foxygen

Reputation: 1388

The colorbox plugin adds an overlay with an id of cboxOverlay. Why don't you just check to see if it exists, and if does - there is a colorbox open, if not, then you can close the other type of popup.

function isColorbox(){

    return $('#cboxOverlay').length;

}

Now you can do this...

$('a.btn').on('click', function(){

    if (isColorbox()){

        $.colorbox.close();

    } else {

        // using your original code for non-colorboxes
        window.close()
    }
});

Upvotes: 1

Related Questions