Preloading an Iframe

RJM62

Touchdown! Greaser!
Joined
Jun 15, 2007
Messages
13,157
Location
Upstate New York
Display Name

Display name:
Geek on the Hill
Is there any way to preload an Iframe referencing a PHP script, which is embedded in an HTML page, so that rest of the page waits until the script is executed before loading?

On a related note, is there any way to substitute some other content for the Iframe if the script doesn't execute because of failure to connect to a third-party feed? (In other words, if the feed is down and the connection times out, some other local content will be embedded.)

Thanks,

Rich
 
Is there any way to preload an Iframe referencing a PHP script, which is embedded in an HTML page, so that rest of the page waits until the script is executed before loading?

On a related note, is there any way to substitute some other content for the Iframe if the script doesn't execute because of failure to connect to a third-party feed? (In other words, if the feed is down and the connection times out, some other local content will be embedded.)

Thanks,

Rich




the answer to both questions lies in creating an object that holds the data. if it is null, display the alternate content. if i werent typing on my phone and about to go to class id be more specific, but that should point you properly
 
the answer to both questions lies in creating an object that holds the data. if it is null, display the alternate content. if i werent typing on my phone and about to go to class id be more specific, but that should point you properly

Thanks. I figured that out for the second question, actually. I'm not sure how to make it work for the first, but I'll work on it.

Thanks again,

Rich
 
There should really be no reason to use an IFrame in the first place. It is deprecated in XHTML 1.0 strict and above I don't know what you are trying to do exactly, but there sounds like there are definitely better ways to do it? Explain yourself more.
 
Sounds like a strange and magical reason to use AJAX to do what you're after.

At the very least, it sounds like some JS wrangling in your future. Agree, though, more info needed in order to prescribe any sort of fix :)
 
Actually, there are several reasons I asked.

One is to come up with an easy way that someone can paste some code on a (non-PHP) page without having to add handlers, and seamlessly embed a contact form from my server onto their page. It would be processed and spam-filtered on my server. An IFrame seemed a relatively simple way to do this.

There are other ways, of course. But the market I'm targeting includes small business owners and others who manage their own sites and have only the barest knowledge of coding. If I can write a script that will spit out a few lines of code for them to paste, and they simply have to paste those lines where their form used to be, that would be ideal. But I'm aso toying with the idea of maintaining a backup mailer script on their server in case network or other issues render mine unavailable. That shouldn't happen very often because of the mirroring, but nothing's perfect. Nonetheless, it's really something I'm pondering, rather than something truly necessary.

The second reason has to do with ad rotation, and I've already figured out a better way.

The third has to do with embedded weather information on a site and how to get an alternate feed if the main one goes down, but I've decided to work that one into the script itself.

Nonetheless, any ideas will be gratefully and graciously received. I am well aware of the gaps in my coding knowledge. My advantage is that this being a midlife career change for me (my original training was in electronics), I also have the maturity and good sense to listen to people who are smarter than I am -- especially when they share their wisdom for free. :p

-Rich
 
I'll stick with the contact form example, since it's straightforward and I can make the most assumptions about it :D

You asked about limiting the rest of the pageload pending the iframe load. This is the stickiest part of the whole thing, and will chafe your "one set of tags to paste for the code illiterate" idea.

If the idea was to replace an existing form from form to /form tag, an iframe will work fine, but it's going obsolete as was mentioned, and programmatic control of iframes can get really hairy (especially in IE) -- a few techniques come to mind:

1. The iframe you mentioned. This has no way to control the site load order without some fancy js, but it really is a blunt tool that achieves what you're up to. You could make the iframe "initial" url something that instructs the user to "Please Wait...", then swap out the src with javascript and flip the iframe to different content.

2. You can AJAX in the form content into a div layer. The "default" content can be a "Please wait..." or other instructive language. This works nicely because the business site needs only add the js include file (that you provide, or, even host on your site) and the div tag. This adds a rudimentary way to stall the user from clicking madly around and foiling your plans :)

3. Tell the site dude to just change their links to link to your form script on your page, thus giving you real ultimate power. The trouble here is now you need to consider their existing site style, which may be problematic, as you're taking on additional work for yourself (bad juju)

I can't gauge your skill, so I apologize if you know this already, but AJAX has gotten really easy nowadays by using a js script library like prototype or jquery. If you haven't dabbled with it or aren't sure what I'm talking about, AJAX is a way to have the browser send an asynchronous call out to a separate URL, "behind the scenes" and fetch the data as an object. It gives you programmatic control over page objects and still gives you access to outside content. Everything balls up into javascript, and you can either manipulate the DOM or just flood-replace tag content (such as a div.innerHTML sort of thing)

Also it's cross-platform capable and rather refined nowadays.

The level of control you seek still smells like AJAX to me, but it's not a stone tool -- it will require some engineering up front -- but what control imposition doesn't? :D

$0.02, you can PM me if you want some code ideas.. it's a weird buzz to combine my two loves by talking nerdy in an aviation forum... :smilewinkgrin:
 
I'll stick with the contact form example, since it's straightforward and I can make the most assumptions about it :D

You asked about limiting the rest of the pageload pending the iframe load. This is the stickiest part of the whole thing, and will chafe your "one set of tags to paste for the code illiterate" idea.

If the idea was to replace an existing form from form to /form tag, an iframe will work fine, but it's going obsolete as was mentioned, and programmatic control of iframes can get really hairy (especially in IE) -- a few techniques come to mind:

1. The iframe you mentioned. This has no way to control the site load order without some fancy js, but it really is a blunt tool that achieves what you're up to. You could make the iframe "initial" url something that instructs the user to "Please Wait...", then swap out the src with javascript and flip the iframe to different content.

2. You can AJAX in the form content into a div layer. The "default" content can be a "Please wait..." or other instructive language. This works nicely because the business site needs only add the js include file (that you provide, or, even host on your site) and the div tag. This adds a rudimentary way to stall the user from clicking madly around and foiling your plans :)

3. Tell the site dude to just change their links to link to your form script on your page, thus giving you real ultimate power. The trouble here is now you need to consider their existing site style, which may be problematic, as you're taking on additional work for yourself (bad juju)

I can't gauge your skill, so I apologize if you know this already, but AJAX has gotten really easy nowadays by using a js script library like prototype or jquery. If you haven't dabbled with it or aren't sure what I'm talking about, AJAX is a way to have the browser send an asynchronous call out to a separate URL, "behind the scenes" and fetch the data as an object. It gives you programmatic control over page objects and still gives you access to outside content. Everything balls up into javascript, and you can either manipulate the DOM or just flood-replace tag content (such as a div.innerHTML sort of thing)

Also it's cross-platform capable and rather refined nowadays.

The level of control you seek still smells like AJAX to me, but it's not a stone tool -- it will require some engineering up front -- but what control imposition doesn't? :D

$0.02, you can PM me if you want some code ideas.. it's a weird buzz to combine my two loves by talking nerdy in an aviation forum... :smilewinkgrin:

Thanks. I shall do that.

I do know what AJAX is and it's one of the things I'm learning, but I haven't used it on any production sites. I've spent most of my time the past year boning up on PHP and hardening my earlier scripts, which only by the grace of God weren't hacked a long time ago, seeing as how poorly they were written, in retrospect.

Thanks again,

-Rich
 
AJAX doesn't really require much knowledge.

AFAIK, it is one javascript call to where you put in a php page to be loaded, and the id of the div to have it loaded into with prototype/jquery/mootools...

I haven't really done any web stuff in a while though. Not only do these javascript libraries make it easier, but it makes it much more cross-platform as they are already fine-tuned for some standard non-conforming browser (IE6).
 
I'm actually making more from Web design (if you include the ad revenue from my own sites) than from the tech support business these days. But it's hard to self-train in anything new when you're running two businesses.

I've gotten to the point with PHP that I've coded the last few sites I wrote (including static sites that I could have written in XHTML) in PHP simply because it was easier. But I've never used JS very much, which kinda makes AJAX a challenge.

-Rich
 
Back
Top