Getting Value From Popup Window Using only JS & HTML

前端 未结 1 572
有刺的猬
有刺的猬 2021-01-24 03:16

Is it possible to get a value from a popup window? Additionally I would like to use JS and HTML only, i.e. no PHP. Is this even possible? I\'ve seen other posts on here like thi

相关标签:
1条回答
  • 2021-01-24 03:25

    It works for me (using Firefox 20.0). But the code is really ugly and old though, probably you should study the present standards of MSDN Window to understand how it works in firefox (Window object may change its behaviour in other browsers). Ah, and of course the ECMAScript . But to introuduce one of the multiple solutions, you could try this:
    parent.html

    <input type="text" id="output"/>
    <button id="show">Open</button>
    
    <script>
        document.getElementById('show').addEventListener('click', function(){
            window['output'] = document.getElementById('output');
            window.open('map.html')
        });
    </script>  
    

    maps.html (I changed the extension!)

    <input type="text" id="user_text"/>
    <input id="send" type='button' value'send'/>
    
    <script>
        document.getElementById('send').addEventListener('click', function(){
        window.opener['output'].value = document.getElementById('user_text').value;
    })
    </script>
    
    0 讨论(0)
提交回复
热议问题