javascript - 您可以从同一站点定位 iFrame 中的元素吗?
问题描述
我要做的是在页面上的 iframe 中打开 minicart url,这样我就可以从购物车中获取购物篮总数。我已经能够做到这一点,但是当我尝试定位 iframe 上的内容时,我无法做到这一点。在站点上,当我使用 console.log “pre”时,我确实看到在 html 集合中,innerHTML 确实显示了输出的内容。知道如何或是否能够针对此目标吗?
var iframevar = document.getElementById('freeGiftiFrame');
var elmnt = iframevar.contentWindow.document.getElementsByTagName("pre");
console.log(elmnt)
<iframe id="freeGiftiFrame" class="cartPopout" name="iframe_a" height="100px" width="100%">
<html>
<head></head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
{"miniCartCount": 1, "miniCartPrice": "€&nbsp;30,00"}
</pre>
</body>
</html>
</iframe>
解决方案
对于任何有问题的人,添加 = sandbox="allow-same-origin allow-scripts" 对我有用
推荐阅读
- python - 熊猫 DataFrame.plot() 方法
- c++ - C++ 标准中是否有关于精度和范围的浮点要求
- c++ - 在c ++中将字符串words[]转换为double feature[]
- excel - Excel VBA - 插入新行后向下拖动公式和格式
- mysql - mysql STR_TO_DATE() 函数结束字符的问题
- javascript - DraftJs:使用实体键替换实体
- aggregate - Azure 数据资源管理器分区策略
- oracle - 加入 3 个表不起作用,我应该使用以下子查询吗
- .net - 如何在 Nuget 包中包含 resx 文件
- spring - 使用 InboundChannelAdapter 动态创建多个 SftpInboundFileSynchronizingMessageSource bean