从iframe内部获取iframe属性数据



我想知道是否有可能从使用Javascript的iframe内部获得iframe属性。

例如,假设我有:

<iframe src"google.com" class="myClass" id="myId"></iframe>

如果我想从iframe内部抓取class属性(MyClass)的值,我怎么能做到呢?

我试过window.class&window.className.

PS:如果这个问题在我道歉之前被问到,我已经看过了,我无法找到一个回答它。

不能使用window.className获取属性值。

用这个…

const iframe = document.getElementById("myId");
iframe.getAttribute("class"); //<-you can select any attribute with this method
//or
console.log(iframe.classList)

最新更新