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;
}, 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


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).

  • if the answer below has resolved the issue, please mark it with the green tick. If your issue is unresolved, please edit your question to show us what needs to be addressed. – mickmackusa Jan 27 at 10:30
  • @mickmackusa Unfortunately that was long ago. I can't tell what exactly solved the problem. But I do not think the answer on its own, because I usually mark questions even I get them resolved. I eventually managed to solve it with a combination of approaches, which I no longer recall. – Hawk Jan 28 at 10:37
  • That's the trouble with abandoned questions. – mickmackusa Jan 28 at 10:40

You are using getelementbyId,but no Id is set. Instead use:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.