Redirect within an Iframe


I have an iframe which is located inside a webpage. When i click a button within the iframe which does a redirect to a new url, the new url is displayed on the whole page and not only within the frameset.

I am using: this.document.location.href = url;

How can i make sure the new url would open within the framset only?

Who is Participating?
Michel PlungjanIT ExpertCommented:
If you use a link, change it to

<a href="#"
onClick="location.href = url; return false">Click</a>

the return false will stop the parent page from reloading
Use this
window.location.href  = url ;
the new url will open on the same window by default not unless your new url breaks frame or has a target pointed to "_top".
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

"your new url breaks frame"  --> "your new url has a script which breaks frame"

btw, do you own the new url page?
RelegenceAuthor Commented:
I am sorry, I just realized that the problem is slightly different:
The Iframe is located at the bottom of the parent page. When redirecting, the focus of the parent page is set to the iframe so that it looks at the top. But, if you scroll up you can see the rest of the parent page.
How can i redirect and live the focus at the same position?
Thank you
or you may try this

document.getElementById(yourIFrameID).src = url;
RelegenceAuthor Commented:
I don't own the parent page.
The parent page which holds the Iframe is managed by someone else whom i gave the url to the iframe.
The iframe contains buttons that cause redirect to the same Iframe.

The question is why after redirect the focus of the parent page is moved to the iframe?
RelegenceAuthor Commented:
Just what i needed. Thanks!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.