简体   繁体   English

无法设置属性innerHTML错误

[英]Cannot set property innerHTML error

I am trying to automate the process of opening an external site from a button of an internal site that I created, but I can not reference the document I created, follow the code below, tried several times and could not, any help is valid, thank you so much. 我正在尝试通过我创建的内部站点的按钮来自动化打开外部站点的过程,但是我无法引用我创建的文档,请遵循以下代码,尝试了几次,并且没有任何有效的帮助,非常感谢。

 <!DOCTYPE html> <head> <title>Principal</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <script src="\\\\fswcorp\\ceic\\ssoa\\gaacc\\System\\JQuery\\jquery-3.2.1.min.js"></script> <script src="\\\\fswcorp\\ceic\\ssoa\\gaacc\\System\\jQueryMask\\dist\\jquery.mask.min.js"></script> <script src="\\\\fswcorp\\ceic\\ssoa\\gaacc\\System\\jQueryUI\\jquery-ui.js"></script> <script> $(document).ready(function() { $("#dateBegin").mask('00/00/0000'); $("#dateEnd").mask('00/00/0000'); $("#buttonDownloadBRScan").click(function() { $windowopen = window.open(); $windowopen.location.href = "https://www.fdibr.com.br/autenticacao/autenticacao/login"; $test = $windowopen.document.getElementById("usuario").innerHTML = "7478704"; }) }); </script> </head> <body> <div class="dataInput"> <label id="labelDateBegin">Data Inicial</label> <input id="dateBegin" type="date" /> <label id="labelDateEnd">Data Final</label> <input id="dateEnd" type="date" /> </div> <br><br> <button id="buttonDownload">Download</button> <button id="buttonDownloadBRScan">Download BRScan</button> </body> 

Assuming you have access to that domain in the window you're opening (same origin policy), you have to wait for the window to finish opening first before accessing elements inside. 假设您可以在要打开的窗口中访问该域(相同的原始策略),则必须等待该窗口首先完成打开,然后才能访问其中的元素。

$("#buttonDownloadBRScan").click(function(){
  const w = window.open('https://www.fdibr.com.br/autenticacao/autenticacao/login');
  w.addEventListener('DOMContentLoaded', () => {
    w.document.getElementById("usuario").innerHTML = "7478704";
  });
})

Try something like this: 尝试这样的事情:

<input id="yourID" type="button" onclick="open_page()" value="Your Message Here"/>

<script>

    function open_page () {
        window.open('Your Webpage');
}

</script>

外部站点和内部站点具有不同的域,您不能直接从内部站点修改外部站点内容。可以使用window.postMessage,也许可以解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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