cancel
Showing results for 
Search instead for 
Did you mean: 

how to fix error/success message not hide after refresh or redirect to another page ?

SOLVED

Re: how to fix error/success message not hide after refresh or redirect to another page ?

Hello @yagnik_solanki1 

After deleting a cookie record called "mage-messages", The old message won't be shown again.

I used the following code to remove it programmatically

...
private $_cookieManager;
...
public function __construct(    ...
    \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
    ...
    $this->_cookieManager = $cookieManager;
}
...
private function _deleteMessage() {        
    $this->_cookieManager->deleteCookie('mage-messages');
}
...


I hope this solution will help you

Re: how to fix error/success message not hide after refresh or redirect to another page ?

Hello @yagnik_solanki1 

After deleting a cookie record called "mage-messages", The old message won't be shown again.

I used the following code to remove it programmatically

...
private $_cookieManager;
...
public function __construct(    ...
    \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
    ...
    $this->_cookieManager = $cookieManager;
}
...
private function _deleteMessage() {        
    $this->_cookieManager->deleteCookie('mage-messages');
}
...


I hope this solution will help you

Re: how to fix error/success message not hide after refresh or redirect to another page ?

Hello @yagnik_solanki1  ,

After deleting a cookie record called "mage-messages", The old message won't be shown again.

I used the following code to remove it programmatically

...
private $_cookieManager;
...
public function __construct(    ...
    \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
    ...
    $this->_cookieManager = $cookieManager;
}
...
private function _deleteMessage() {        
    $this->_cookieManager->deleteCookie('mage-messages');
}
...


I hope this solution will help you

Re: how to fix error/success message not hide after refresh or redirect to another page ?

Hello @yagnik_solanki1 ,
After deleting a cookie record called "mage-messages", The old message won't be shown again.

I used the following code to remove it programmatically : - 

...
private $_cookieManager;
...
public function __construct(    ...
    \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
) {
    ...
    $this->_cookieManager = $cookieManager;
}
...
private function _deleteMessage() {        
    $this->_cookieManager->deleteCookie('mage-messages');
}
...


I hope this solution will help you

Re: how to fix error/success message not hide after refresh or redirect to another page ?

Hello @yagnik_solanki1 ,

there is a cookie record called "mage-messages". After deleting it, the old message won't be shown again.

Re: how to fix error/success message not hide after refresh or redirect to another page ?

@syedkamranef82  Where to add this code, from where and when to call this function

Re: how to fix error/success message not hide after refresh or redirect to another page ?

I had the same problem, so I found out it is not a good idea to change a cookie with js that you initially created with PHP, so I developed a GraphQL API that deletes the message cookie. I called this API with jquery in messages.js where you usually would set mage-messages "", and it worked.