This question is based on previous question here where I managed to populate username from the opener/source to the destination window, using the following code in the destination window using postMessage. The code on the destination side is:
window.onload = function(){
window.opener.postMessage('giveMeUsername', '*');
};
/**
* Event to catch opener messages
*/
window.addEventListener('message', function(event) {
if(event.origin !== 'http://example.com') return;
var message = event.data;
jQuery('input#username').val(message);
}, false);
Now there are two requirements I need to do as follows:
click button programmatically
I need to trigger click event of login button once the window is loaded if the password field is not empty. I tried to add this line to my code
document.getElementById('loginbtn').click();
But nothing happened. In fact, I'm not sure if the button has an ID or name, as when I inspect the element, I find this line
<button type="submit" style="float:right" class="button loginbtn""><?php echo JText::_('JLOGIN'); ?></button>
So the question is :How to trigger this button on window load at the end of the script above?
Select Language Programmatically
I concatenate the language code that is used in the source as `var msg = username+'-'+LangCode'
In the destination side, I'm able to extract the language code, but I got stuck at how to use it to change the language value from the list (assume the code is a
then the selected language should be English
... etc).