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">

asked Dec 26, 2013 at 16:40
2
  • possible duplicate of change src of iframe and then reload the iframe 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.

answered Dec 26, 2013 at 16:51
Sign up to request clarification or add additional context in comments.

1 Comment

So location.href target to current document !! for this iframe is current document. nice thanks :)
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;
answered Aug 3, 2018 at 9:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.