获取iframe src参数从内部iframe本身,如果我没有它的id属性,但我有名称属性

Get iframe src param from inside the iframe itself if i dont have its id attribute but i have name attribute

本文关键字:属性 iframe 有名称 id 如果 参数 src 内部 获取 本身      更新时间:2023-09-26

我怎么能得到iframe src参数从内部iframe本身,如果我没有它的id属性,但我有它的名称属性?

例如:

<iframe name="ambiguous" src="some src here"></iframe>

您可以这样访问:

document.getElementsByName("ambiguus").item(0).getAttribute("src");

注意:

如果名称在您的HTML页面

中是唯一的,则此解决方案有效
参考

  • getElementsByName MDN

你可以试试frameElement。SRC在控制台如果你在iframe