8

I know there are question have been asked around resembling to this one, but still I am not getting proper concept of this. I am currently loading an iframe through javascript in following manner:

jQuery('.out-div-login').html("<iframe id='parent' frameBorder='0' width='320' height='500' src='"+_url+"'></iframe>");  

Which is working fine. (its cross domain). After loading my application inside given iframe, I want to come back to original state where .out-div-login was loading iframe into parent html.
From outside of iframe I can do this by accessing iframe using its id attribute, but not from the inside. Is there any way I can reload the iframe by giving its src again ? or by above code but from inside the iframe ? Thanks.
Update
I have tried below code without any success as of now:

var ifr = $('iframe[id="parent"]');  

from one of js file inside iframe with id parent. when I do console.log(ifr) it gives in firebug something like this Object[] instead of <iframe id="parent">

2
  • possible duplicate of change src of iframe and then reload the iframe
    – Sebi2020
    Commented Dec 26, 2013 at 16:43
  • 1
    @Sebi2020 Thanks for your response, but code in given link works only when we try to execute from outside iframe.!! I have tried this, I am not even able to get iframe reference from inside the current iframe Commented Dec 26, 2013 at 16:46

2 Answers 2

21

You should use location.href inside the iframe. That should work. set location.href in the iframe to your new location.

1
  • So location.href target to current document !! for this iframe is current document. nice thanks :) Commented Dec 26, 2013 at 16:56
1

The url query string (?xxx) should also be kept in the new url, so the whole solution should be:

location.href = "new_link_url" + location.search;

Not the answer you're looking for? Browse other questions tagged or ask your own question.