Forum Moderators: open

Message Too Old, No Replies

Iframe onChange substitute

         

Drag_Racer

4:51 pm on May 8, 2007 (gmt 0)

10+ Year Member



I am struggling trying to find a solution to this delima. I have a page with an iframe. The document in the iframe comes from a different domain which I can not alter the contents. I have an onLoad event on the iframe which triggers my script when the page loads but I need to fire the script everytime the document in the iframe changes. I'm almost at the point of killing the iframe and rebuilding it everytime but that has issues on its own...

Anyone have any ideas? I searched for ever and a day on Google with no help...

Dabrowski

6:19 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A difficult one, I'm assuming the code of the IFRAMEd page is beyond your control?

Not really sure about this one at all. You can't even reload it that I'm aware of as you can't access the Location object to do a reload().

I think AJAX could help you, I'm not too well up on the details as I haven't used it myself, but I believe you could use it to fill in a DIV on your page that you can then access.

Sorry can't be more help.

Drag_Racer

9:53 pm on May 8, 2007 (gmt 0)

10+ Year Member



thanks for the post.

I thought about a div, but I'm kind of stuck with an iframe with no access to the framed document at all.

I think I'm going to cheat and put a server-side script to grab the remote document so the domain will be the same on the framed document, but that may put me over the edge on a service agreement. it's a grey area so I'm not sure yet...

Dabrowski

10:20 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm, a proxy. Sneaky! I have an instance whereby I require images from a non-https site, on a https site.

If you use a normal img tag IE complains that some items are not secure. I used the same thing - a proxy to go get my images for me on the secure site.

If you can get away with it go for it, it's your best option. As long as you don't modify their code in any way, or change the presentation of the page, I doubt you'll be in breach of any SLA.

Drag_Racer

5:52 am on May 9, 2007 (gmt 0)

10+ Year Member



well, that didn't work...

the first try on the proxy I got a violation warning... opps there's my answer but I didn't give up that easy.

I passed all the headers I could thing of both ways, passed on the cookies, and hacked the referer. This got me the page but it has subtle differences which throws big warnings to me...

The only thing I can think of is they are checking ip from an image which they have in the document, either way I running...

If its that hard to get the correct page then I'm doing a bad thing... These guys have too many lawyers, the client will just have to suck it up and do without on this one.

Drag_Racer

5:56 am on May 9, 2007 (gmt 0)

10+ Year Member



should'nt changing the SRC attribute of the iframe cause the onLoad event to fire? I got a no in FF

Dabrowski

12:00 pm on May 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've not tested it, but I imagine changing the src attribute should cause a new page to load, but any onload event would only fire inside that document, hence out of scope.

I've done a little reading on the IFRAMEs onLoad event, apparently it's buggy and inadvisadble to use it.

What exactly do you want to do when it's loaded?

Achernar

11:50 pm on May 9, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've a site with this type of design.

It looks like this:

<iframe src="default_src.html" onload="javascript code"></iframe>

Since the page in the iframe is not from the same domain, you won't be able to access the content from the main page. But you can still know that a page has finished loading.

onunload="" should work too if you need to know if the browser is about to load a new page in the iframe.

Drag_Racer

8:56 am on May 12, 2007 (gmt 0)

10+ Year Member



What exactly do you want to do when it's loaded?

resize the iframe to match the size of the new document. this normally can't be done due to the need of reading the framed doc, but the src attribute of the iframe contained enough info to let me know what is in the doc enough to make a rough estimate of the needed size.

I'm stuck in a situation that I can't stand on this one. The owner is too ignorant to understand what makes a usable web site and allows the designer to give me a tiny area to work with to squeeze a ton of info into. The owner wants a lot of white space for a 'free flowing' site they say. I see all this graphis stuff all over the pages taking up all this great realestate, then I'm forced to cram all the content into 25% of a page... just stupid. I had to remove half of the functionality and 60% of the data to make it fit. NEVER,NEVER,NEVER sacrifice functionality for design, but do they listen...

I've had the main program finished for 2 months just waiting on them. They want to launch on Mothers Day, oh wait thats in 2 days. They hire a webmaster 8 days ago to build the web pages... I have to hold their hand just to get things like a link on the home page bypassing the flash animation index... gee, why is it I'm still on my computer at 1:50 in the morning on a FRIDAY... #$#%*^(*&^&#$##^*

wait, there is a brick wall over there, let me go run into it a few more times...

Drag_Racer

8:58 am on May 12, 2007 (gmt 0)

10+ Year Member



ok, I feel better now...

Achernar

11:46 am on May 12, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



resize the iframe to match the size of the new document. this normally can't be done due to the need of reading the framed doc, but the src attribute of the iframe contained enough info to let me know what is in the doc enough to make a rough estimate of the needed size.

The src attribute of the iframe DOM element isn't updated when the content of the frame is modified (by clicking links), and since you've said that the framed document is from another domain, you won't have access to its location.href property.
Sincerely I don't see how you could achieve what you're trying to do.

Dabrowski

12:14 pm on May 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm, here's an interesting theory.....

Imagine your IFRAME was a DIV, you'd set overflow auto to make it scroll. Now, assume that in these grand days of the DOM, the IFRAME is almost no different, just has overtflow auto as default?

Maybe you could just set

IFRAME { overflow: visible; }
to make it stretch?