Reputation: 45
I'm making a Wordpress site and I need that a page load itself in an iframe inside of it.
It's like the inception movie!
My problem is that urls of the pages are dynamic.
Actually I need a script that append an iframe in a specific div...I've tried with this line of code but it doesn't work:
jQuery(".reloaddivxxx").append(" <iframe src=\"(window.location.href)\"></iframe> ");
I'm not sure if it's clear what I need to do... I need to create an iframe that loads the page where is placed and get the url of that page dynamically.
Upvotes: 0
Views: 117
Reputation: 952
You can set the url of an iframe with JavaScript, after getting the URL of the current page.
var url = window.location.href;
var iframe = window.frames[0];
iframe.location = url;
Edit 1:
If you're inserting the iframe dynamically as well, you have to either get the reference to the iframe after inserting it, or before. Here's an example of the latter:
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);
Upvotes: 1
Reputation: 528
Try this
var iframe = document.createElement('iframe');
iframe.style.width = '100px';
iframe.style.height = '100px';
iframe.src = window.location.href;
document.getElementsByClassName('reloaddivxxx')[0].appendChild(iframe);
Upvotes: 0