I have iframe on my site. In this iframe another site is displaying. After submitting form in iframe location.href is changed. It leads to top level window redirect.
So, I want to change location of iframe instead of changing location of top-level window.
How can I do that?
Thanks!
Related
How can I make it so that when I click on another page in an iframed it opens within the iframe? I own both the website being iframed and the site with the iframe, so if I need to do something with the configuration of either that is fine. Thanks for your time!
That is the default behaviour.
So don't:
Use JavaScript to trigger non-standard link behaviour
Use a target attribute on the link
Use a target attribute on a <base> element
Use an CSP to block the page from being loaded in a frame
Use an X-Frame-Options header to block the page from being loaded in a frame
On the site that you are embedding the iframe on, enter this code:
<iframe src="Your iframe url" width="100%" height="100%" name="search_iframe"></iframe>
On the site within the iframe insert this code, and make sure the url is the other link you want to redirect to in the iframe:
<html>Link_name</html>
This should let you redirect in an iframe, but remember to add the href code for each link, otherwise it will open the link outside of the iframe.
I want to click on a link inside iframe onload with the help of JavaScript, I have a site loading inside an iframe, now I want to click a link of a particular div (ID) on page load. The link is inside the iframe.
Actually I'm trying to change the language of the website which is loading in the iframe, the site has gtranslate plugin installed and has different language flag at the footer of the site.
Basically is it possible to force a page to be translated when the page loads?
The Same Origin Policy prevents you from scripting an Iframe from a different domain.
Possible answer here
I have a question about changing output of iframe. My site loads a front page (wordpress) where the entire content block is an iframe. Can I manipulate the output of the iframe from the wordpress side?
Say I want to scroll to an id tag in the content of the iframe, can I create a link on the frontpage outside the iframe that goes there?
Another example could be to pre-fill an input field in the iframe by clicking a menu link in wordpress, is it at all possible?
It can depend on whether the iframe is cross-origin or not (i.e. whether the src attribute on the iframe is on the same domain as your wordpress site).
If it isn't - then you can simply access the iframe contents using javascript from the parent window, e.g. (in the parent window):
const iframe = document.getElementById('<your-iframe-id>');
const iframeDoc = iframe.documentElement || iframe.contentWindow.document;
doThingsWithIframeContents(iframeDoc);
If it is cross-origin - then you will need to pass messages to a script you control inside the iframe document. That script will then manipulate the contents of the iframe itself. Without going into too much detail, take a look at https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage.
Edit: Actually, take a look at this other SO post that is relevant to this case: How to communicate between iframe and the parent site?
Hope that helps!
I have a page that is opened in iframe, that page has a modal/popup in it. I want to access the parent page (opened in iframe) values, in modal using jquery or javascript. any ideas how could I do that?
I have tried it using window.parent.document but it takes me to the index page, while I want to remain inside the body of page opened in iframe. And window.parent.$('#someId:checked') gives me [prevObject: r.fn.init(1)].
I have a html based application and sometimes my html app needs to open another url in iframe.
the problem is that the third party url in the iframe open a new window too with the same content, the same url.
so how can i prevent it?
This seems like an iframe breakoutscript in the thirdparty page. A few links about a solution to this problem.
http://stuntsnippets.com/prevent-iframe-breakout/
http://www.zimbio.com/Web+Design/articles/1110/How+prevent+iFrame+breakaway
How to prevent IFRAME from redirecting top-level window