简体   繁体   中英

Track submit event in new window javascript

I open new window with javascript. I mean function window.open . I know that I have object of this window. This new window has <form> with checkbox and submit button. So I wonder can I track submit form event and check if checkbox was checked in this new window.

window.open('http:some_external_url','new_window','width=800,height=600,resizable=yes,scrollbars=yes')

And form in new window:

<form method='post'>
    <input type='checkbox' name='somename' />
    <input type='submit' name='submit_button' />
</form>

Can anyone help please?

It is possible if the page opening the window and the page that is opened are from the same origin...

var win = window.open('form.html', 'formwin');
win.addEventListener('submit', function () {
    console.log('parent: submit')
});

Demo: Plunker

If they are not, the the browser security policy won't allow you to access the contents of the new window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM