Get element by Id from another page

后端 未结 3 1535
慢半拍i
慢半拍i 2021-01-16 12:02

I need to change content of page1 if page2 contain specified element. This code works great if I get id from the same page

if (document.getElementById(\"page         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-16 12:34

    Think of it this way. JavaScript runs in the browser, say, Chrome. Chrome can see the page that is currently loaded, but has no knowledge of the html files that are still on the server, until they are brought into the browser. What you could do is have an iFrame containing logged.html that isn't visible (maybe 1x1 pixels, or a fixed position with a position off the page (left: 4000px). Then you can refer to the iFrame and get the element from there, this one explains how to reference an element in an iFrame: getElementById from iframe

提交回复
热议问题