Gadgetto Posted January 11, 2020 Share Posted January 11, 2020 I have a PW panel with a button element inside. When this button is clicked, the panel should close and the button action (href is triggered via JavaScript) should be executed in the main window (from where the panel was opened). In the current state, when the button is clicked, the action is processed within the panel, which is not what I want. Here is the button code: /** @var InputfieldSubmit $btn */ $btn = $modules->get('InputfieldButton'); $btn->attr('name', 'delete_discount'); $btn->href = $this->snipWireRootUrl . 'discounts/?id=' . $item['id'] . '&action=delete_discount'; $btn->aclass = 'DeleteDiscountButton'; $btn->text = $this->_('Delete discount'); $btn->icon = 'trash'; $deleteButton = $btn->render(); Here is the JS part which is triggered when button is clicked: $('.DeleteDiscountButton').on('click', function(e) { e.preventDefault(); var a_href = $(this).attr('href'); ProcessWire.confirm( discountActionStrings.confirm_delete_discount, function() { // dialogue OK click window.location.href = a_href; } ); }); Any hints on how this could be done? Link to comment Share on other sites More sharing options...
dotnetic Posted January 11, 2020 Share Posted January 11, 2020 As the content of the panel is a totally different document (Iframe), than in the opening document your function has to be modified. $('.DeleteDiscountButton').on('click', function(e) { e.preventDefault(); var a_href = $(this).attr('href'); ProcessWire.confirm( discountActionStrings.confirm_delete_discount, function() { // dialogue OK click window.parent.document.location.href = a_href; } ); }); The key is using window.parent.document, which refers to the document that opened the panel. 1 Link to comment Share on other sites More sharing options...
dotnetic Posted January 11, 2020 Share Posted January 11, 2020 If you don't need to support old browsers like IE, than it is also better to use "let" to define javascript variables. Link to comment Share on other sites More sharing options...
Gadgetto Posted January 11, 2020 Author Share Posted January 11, 2020 4 hours ago, Jens Martsch - dotnetic said: As the content of the panel is a totally different document (Iframe), than in the opening document your function has to be modified. $('.DeleteDiscountButton').on('click', function(e) { e.preventDefault(); var a_href = $(this).attr('href'); ProcessWire.confirm( discountActionStrings.confirm_delete_discount, function() { // dialogue OK click window.parent.document.location.href = a_href; } ); }); The key is using window.parent.document, which refers to the document that opened the panel. Great, this works - thank you! 1 Link to comment Share on other sites More sharing options...
Gadgetto Posted January 11, 2020 Author Share Posted January 11, 2020 4 hours ago, Jens Martsch - dotnetic said: If you don't need to support old browsers like IE, than it is also better to use "let" to define javascript variables. I know Jens, but I'd like to use same references as PW uses. An PW is not yet on ECMAScript 6. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now