Set value element to a other page called by window.open()

前端 未结 2 1885
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 07:00

I\'m struggling to implement this case, I really appreciate your help.

UPDATE :

page1.html



        
相关标签:
2条回答
  • 2021-01-21 07:46

    First of all javascript is case sensetive, and n is missing. so replace getElemetByID with getElementById.

    Second is that the code executes immediately and doesn't wait the page to load. You must wrap your code in window.onload :

    newWindow.onload = function(){
         newWindow.document.getElementById('one').value='xxx';
    }
    

    there's 3 bugs in the update:

    1. function in detailsWindow.onload = function must be declared with detailsWindow.onload = function() to work.
    2. your end script is must be replaced from <script> to </script>
    3. you are missing detailsWindow in document.getElementById('one').value = 'test'; it must be detailsWindow.document.getElementById('one').value = 'test';
    0 讨论(0)
  • 2021-01-21 08:02

    // page1.html

    <script>
    var newWindow = window.open('page2.html', 'formUntukUpdate', 'width=400,height=350');
    newWindow.onload = function(){
        newWindow.document.getElementById('one').value = 'ok 2';
    };
    </script>
    

    // page2.html

    <input type="text"  id="one" value="ok" />
    
    0 讨论(0)
提交回复
热议问题