'Mousedown is not triggering from a checkbox in modal popup to an outside popup button
The modal popup is a drupal dialogbox which is coming inside an iframe. I need to trigger mousedown on a submit button which is outside iframe when checkboxes are clicked in popup. I wrote the below jquery, but the button is not affecting.
$('#modal-popup .form-boolean--type-checkbox').click(() => {
let body = $(window.parent.document.body);
console.log(body);
body.find('[name="add_more_button"]').mousedown();
});
$(window.parent.document.body).find('[name="add_more_button"]').mousedown(); works in the console but not from jQuery. Why is this?
Solution 1:[1]
I got the solution after hours of research. From iframe we can call a function of parent window. I used below code and working fine.
$('#modal-popup .form-boolean--type-checkbox').click(() => {
window.parent.parentFunction();
});
window.parentFunction = function(){
$('[name="add_more_button"]').mousedown();
}
I used separate function for triggering the button and used window.FuntionName name for this. From iframe popup, I called this function to trigger mousedown using window.parent.FunctionName()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Swati Dhurandhar |
