auto-size iframe cross domain - javascript

I am making a web widget using iframe and javascript and i would like to make my iframe resizable to it´s content (which is loaded from other domain).
I have done some search(inclusive here at StackOverflow) and i find a couple of topics but i couldn´t find any conclusions about this issue.
Is this possible or not?
Because atm i have to set my iframe height to the maximum height of the content which in some steps of my widget gives a big white space at the bottom which dont look very good.
Note all the interactions inside the widget iframe are done completely with ajax. (The iframe src is just one html page).

Take a look at this :) Also you could use postMessage - there is a crossbrowser jQuery plugin.

Hand-coding the postMessage stuff yourself is a walk in the park. You don't need a framework to do it for you. Here is an easy example on stackoverflow: cross-domain iframe resizer?

Related

iFrame is not fixing correctly in android device

i made a android app using it's web view. there contain a lot of functions. payment integration etc. i integrate this payment method using a third party tool. This tool provide an external html page. when i load this page directly in to my web view it's work nicely.
but after i got a requirement that there need a back button in the payment page. after then i add this page using an IFRAME. after there is number of issues came related to the design. the content is not fitting in the IFRAME also there is not displaying the scroll bars.
i tried differant kind of javascript method but no output.
If any solution present for this
Answer to the iframe scrolling problem
1.Zoom in until the iframe portion of the page completely fills the screen.
Tes might activiate the scrollbar and allow you to scroll the iframe.
2.Try double-touching the screen. This means you use two fingers to scroll on the iframe area.
3.If neither #1 or #2 work, try a different browser such as Dolphin, xScope, or Opera.
If none of those three work, try out Firefox. I listed Firefox separately and last because it is slow and resource-intensive on Android, but if it's your only recourse, then use it only when you must.
Can you provide more information on the content not fitting inside the iframe?

How to auto scroll down an iframe 100px every 5 secs?

I would like to know how can I scroll down an iframe 100px every 5 secs using maybe javascript. I know that there is a window.scrollTo(x,y); but how does this change to an iframe?
The iframe is an external page.
Any possibility of software to download that does this thing?
This isn't possible if you do not have control of the external page's code. browsers prevent this type of thing for security reasons. Its considered cross-domain scripting.
Its very easy using a jquery,
Lets say the id of your iframe is testframe then the code for it would be
$("#testframe").scrollTop(400).scrollLeft(400);
Now just wrap it inside an interval and put it inside.
var tick=1;
function scrolldown(tick) {
$("#testframe").scrollTop(tick*100);
}
self.setInterval("scrolldown("+(tick+1)+")",5000);
Note: Just a typo
You can use setInterval to do the scrolling every 5 seconds. the scrolling itsself can be done with this.
Is there an updated version to this method? Not finding it to actually control the content within the http://time.com">
not showing. Thats rather puzzling. So typing iframe inside an iframe makes it go invisible..
If you are building a desktop application (Windows, Linux, not quite sure), I would suggest you to find a component that is the java equivalent of the C# web browser control.
Since this control is loaded in a desktop applicaiton, you have full control over the browser loaded document (e.g. you can manipulate it, without being in a cross domain context).

iframed site accessing frames outside of its own

Background:
I am trying to iframe an entire external website for a project. Some links within this external site are within even more frames. They use js to access the top window and set its location according to the href value of the link, which results in the new page loading completely outside of my iframe (which I would like to avoid).
Question:
Has anyone dealt with this/is there a way to deal with this? Ideally I would like to prevent the iframed site from accessing frames outside of its own.
Note:
As per my knowledge it is not possible but still want to have a second opinion
Thank you very much for any help or insight,
To get around the restriction for the iFrame sources, the only way you can do it by setting up a web proxy script on your website.
<iframe src="proxy.php?url=http://othersite.com/">
you should be able to find some proxy implementation on some script site.

External page - give it JS instructions?

I'm interested in linking to or embedding an external page, scrolling to a specific point. Is this possible, or do cross-browser securities prevent it?
One workaround I've considered is creating the iframe within a div, giving the iframe a negative margin and then overflow:hidden; the container div.
Thanks.
A possible solution could be to use JavaScript to scroll the page. However, if the page you are embedding is on a different domain, you cannot access its content with JavaScript if it is in an iframe (due to the same origin policy). However, if it is on the same domain as the host page, you should be able to access it using JavaScript and then scroll using the window.scrollTo(x,y) method or similar (see this page on MDN).
Also, if the page you are embedding has a named anchor (<a name="blah">) or a block-level element with a specific id (<div id="blah">) at the point you want to scroll to, you can link to it or embed it by using a URL such as http://example.com/page#blah and it will scroll to blah automatically. This is not under the same-origin policy, so you can do something like <iframe src="http://example.com/page#blah"></iframe> and the frame will automatically be scrolled to blah, even if it is not on the same domain as the host.
The "iframe with negative margin" solution you mentioned could work, but that might be hard to implement and would probably cause problems, especially if you want full cross-browser compatibility.

Javascript/iframe/embed/object question

OK, so here is my issue. I'm building a system which will allow people to embed lists of links on their pages. When the link is clicked, i'd like to use something like Lightview or Lightwindow to open it up over the whole window, not just in the iframe.
I don't have access to the page that the user will be embedding this object into. Everything I've tried so far tells me that I can't open anything over the parent window, since I don't have access to it from the iframe or object, javacript security issue.
However, I've seen sites that do that kind of overlay. so it must be possible. If anyone can point me to any resources that could help, that would be great.
if it matters, i'm using Ruby on Rails...
Thanks...chris
It can't be done if the iframe is from another domain than the website, because:
You cannot change the dimensions of
the iframe from within it.
You cannot access the parent
document from within the iframe.
I suggest trying using some sort of JS file people will embed in they're website, in the place they want your links to be (something like Google Ads) and do a document.write to place
your links in their webpage. then, you will have access to the page, and can do a whole lot more :)
is this helping you?
As vsync said, you will have to have the user embed a script instead of the plain HTML.
This script has full control of the page, and if you also want it to be able to communicate with the framed document (your site), then you could use something like easyxdm to do cross document communication.

Categories