Reputation: 237
I have an iframe
and I want to reload the currently displayed page on button press.
HTML:
<iframe id="webView"></iframe>
JS:
function reloadPage()
{
var webView = document.getElementById("webView");
//CODE
}
Inside the reloadPage()
method I tried different solutions:
webView.contentWindow.location.reload();
This just doesn't work because the pages loaded inside the iframe are from a different domain than the main page.
webView.src = wevView.src;
It gives wrong result because it contains the initial url that I set to the iframe, non the current one.
webView.contentWindow.location = webView.contentWindow.location
I was expecting it to not work with urls from different domains (the same as calling reload()), but actually it works and also gives a good result.
Good but not perfect: the location
object holds the current url but strips any parameter.
For example if the frame is currently displaying the following url:
http://www.myserver.com/thatsite/?page_id=11
the location
object contains this url:
http://www.myserver.com/thatsite/
So this one works well as long as there are no parameters in the url.
I rely heavly on urls with parameters (mostly WordPress installations) so i need a way to keep them while reloading.
Anyone knows a solution to achieve this?
Upvotes: 1
Views: 1183
Reputation: 14434
just not possible, see this thread:
and this one
How do I get the current location of an iframe?
Upvotes: 1
Reputation: 201
Since setting location works, you could use location.search to retrieve the GET parameters and reconstruct the URL that way.
Example:
webView.contentWindow.location = webView.contentWindow.location + webView.contentWindow.location.search
Upvotes: 0