我正在创建一个 Wordpress 网站,我需要一个页面在其内部的 iframe 中自行加载。
就像盗梦空间电影一样!
我的问题是页面的 URL 是动态的。
实际上我需要一个在特定 div 中附加 iframe 的脚本...我已经尝试过这行代码,但它不起作用:
jQuery(".reloaddivxxx").append(" <iframe src=\"(window.location.href)\"></iframe> ");
我不确定我是否清楚我需要做什么...... 我需要创建一个 iframe 来加载放置的页面并动态获取该页面的 url。
最佳答案
获取当前页面的 URL 后,您可以使用 JavaScript 设置 iframe 的 url。
var url = window.location.href;
var iframe = window.frames[0];
iframe.location = url;
编辑 1:
如果您也动态插入 iframe,则必须在插入 iframe 之后或之前获取对 iframe 的引用。这是后者的示例:
var url = window.location.href;
// Create the iframe using jquery, and set the url of it.
var iframe = $("<iframe>");
iframe[0].src = url;
// Insert the iframe into the div.
jQuery(".reloaddivxxx").append(iframe);
关于javascript - 创建一个加载与放置位置相同的页面的 iframe - IframeLoop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32566599/