How to close a browser window or tab

How to close a browser window or tab

  
I have a page with a list of cases, the user clicks in one and opens this case in a new tab.

I want for the user to be able to click on a button to close this new tab, instead of just clickin on the "x" in the browser tab (I want to be able to save the case before exiting)

I saw this javascript...

window.open('','_self').close()

But how do I implement that in a button action?

Thanks!

You can either use an ajax with the RunJavascript RichWidgets action for that code, or a Navigate button with "javascript:your_code" as the target.
Sorry, but being a newbie I could not figure out how to perform either of those ideas:

1) I cannot find any "RunJavascript" RichWidget and even if I did, I would not know how/where to place it.

2) I can't type code in the "destination" box for the navigation button. All I can do is to choose a target screen or action.

Can you give me an example how to perform any one of those two solutions?

Thanks.
1. You need to make sure that you have a reference to it, it's in the Rich Widgets eSpace. It is an action (to be used in logic) not a widget (to be dropped on a screen).

2. Change the "Destination" to "ExternalURL" in the list, then give it the JavaScript as the URL. If your eSpace doesn't have "ExternalURL" available, go to your common widget area, right-click, choose "External Site" to create it, then right-click and add a dynamic URL parameter.

J.Ja
Thanks!

Macro101 wrote:

I have a page with a list of cases, the user clicks in one and opens this case in a new tab.

I want for the user to be able to click on a button to close this new tab, instead of just clickin on the "x" in the browser tab (I want to be able to save the case before exiting)

I saw this javascript...

window.open('','_self').close()

But how do I implement that in a button action?

Thanks!

Hi Macro,

How did you implemented this using the RunJavaScript Action?

Thank you and kind regards,

Christopher


Hi Christopher,

Change your button's "Method" property to "Ajax Submit" and, on its click action, call the "RunJavaScript" action as pictured below:

Hi Christopher,

Add the RunJavaScript extension as a dependency to your module and then add the following javascript to the action (closing button/link) in the screen you're want to close:

window.close();

Looks like this:

Hope this helps ;)

Regards,

Jasper

Thanks guys for the quick response.

I plan to invoke it in the preparation just in case I detect a duplicate of the URL being used.

Will it still work?

Currently, I'm testing it but it seems not working.

Can it be used in the Preparation stage?

Thank and regards,

Christopher

Ah,

that's a different requirement all together.


Hi J,

Do you have a suggestion?

Or have read a previous post similar to it?

Thanks and regards,

Christopher

I don't think this will work because this is typically a frontend feature.......preparation is data/backend related and therefor not a logical place to do these kind of things.

Hi,


I don't think you can catch it in the preparation, 

Using Javascript assign a unique id like a guid to the browser window / tab by assigning the guid value to the window.name property. window.name property is unique to each browser window/tab and won't be shared across the windows.

from there you will need to keep track of the guid and session and your activeId...


tbh, it's rather much work and you better solve it by chekcing it when inserting/updating it to the database with versioning for example.


I'm with J... this is sounding worse and worse. This is a bad approach to the issue.

J.Ja

Thanks for the advise guys.

What I did instead is redirection to a Web Screen, informing the user that reusing the same URL is not allowed.

Thank you and kind regards,

Christopher