Alas problem.



  • Call attention to the Alias (synonym) R that was given by the wid.document.write method to be able to summarise it as R(...) ♪

    <HEAD>
      <SCRIPT>
        wid = window.open('','','width=750,height=100,status=yes');
        wid.document.open(); R = wid.document.write;
        R('<HTML><HEAD><SCRIPT>var t;<\/SCRIPT></HEAD>');
        R('<BODY><H1>Новое окно</H1></BODY></HTML>');
        wid.document.close();
      </SCRIPT>
    </HEAD>
    

    <BODY>
    <A HREF="javascript:
    wid.t=window.prompt('Новое состояние:','');
    wid.document.write(wid.t); wid.focus(); void(0);"
    >Изменим значение переменной t в новом окне</A>
    </BODY>

    FireFox works correctly, and the debager in Chrome is fighting.

    R('<HTML><HEAD><SCRIPT>var t;</SCRIPT></HEAD>');

    Uncaught TypeError: Illegal invocation

    Rewrite the script as follows

    <SCRIPT>
    wid = window.open('','','width=750,height=100,status=yes');
    wid.document.open();
    wid.document.write('<HTML><HEAD><SCRIPT>var t;</SCRIPT></HEAD>');
    wid.document.write('<BODY><H1>Новое окно</H1></BODY></HTML>');
    wid.document.close();
    </SCRIPT>

    FireFox also works correctly. Chrome stopped arguing. How is it right to synonym R?



  • In this case, write tied to the context in which it is called, it needs to be used to preserve it. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

    var R = wid.document.write.bind(wid.document);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2