简体   繁体   中英

Is there a way to differentiate between elements with the same ID but in different browser tabs?

Let's say I have my website open in two tabs, and i want to get the element with the id "id", can I somehow get the element in the currently focused browser tab?

document.getElementById("id"); 

seems to get the element that was loaded most recently.

No, since that would be a gaping security hole.

There's a similar question on stackoverflow: Accessing the content of other tabs in browser .

This answer to the linked question provides code to do it, but I had problems in the past with IE, when trying to specify event handlers on the other document (worked fine in Firefox though).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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