/    Sign up×
Community /Pin to ProfileBookmark

Naming Iframes

I’ve bumped into a problem with named Iframes and I’m hoping someone here can suggest a solution.

On my web page, I create an iframe called ‘content’, and I load some of the page content into that space. It has been working well, but a problem is cropping up when I open multiple windows (or tabs) with the same page structure.

This architecture serves the intended purpose well and works without complication most of the time but occasionally, content intended for the ‘content’ space in the active window loads into the ‘content’ space in a background window.

Clearly, because it works most of the time, for each window opened, the browser must assign some sort of internal pointer so that it can control each window.

Is there a way to access the internal pointer so that this…
target=’content’
becomes
target=’pointer.content’ or similar ?

An alternative might be to assign a unique name to the ‘content’ space when a window is opened, but I have no idea how to detect and track without resorting to random numbers as names (and even then, I’d need to keep track of random numbers currently in use).

Any suggestions?

to post a comment
HTML

10 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 13.2008 — iframes are listed in the window array, essentially there's no difference between a window and an iframe.

Using JavaScript you would reference: [COLOR="Blue"]self.content.location='foo.htm'[/COLOR]

Try adding a base element to the document: [COLOR="Blue"]<base target="_self">[/COLOR], although this may affect other links within the document!

Alternatively combine target with JavaScript:[COLOR="Blue"]<a href="foo.htm" target="content" onclick="self.content.location=this.href; return false;">[/COLOR]
Copy linkTweet thisAlerts:
@chestertbauthorDec 13.2008 — Thanks Fang,

The problem occurs when a link in the top document targets the iframe.

Something like this...

[code=html]<body>
<a href='somefile.php' target='content'>A Link</a>
<iframe name="content" id="content" src="afile.php" border="0" frameborder="0" scrolling="auto" width="500" height="400"></iframe>
</body>[/code]
Copy linkTweet thisAlerts:
@FangDec 13.2008 — Did you try using the base element?
Copy linkTweet thisAlerts:
@chestertbauthorDec 14.2008 — I'm not sure I'm with you on the <base> element.

Does it go in the top page

<base target='content'>

Or does it go in the page that loads in the content

<base target='_self'>

?

And what will happen to other links on the page? (They all specify a target so I'm guessing they won't be effected..yes?)
Copy linkTweet thisAlerts:
@FangDec 14.2008 — In the top document.
Copy linkTweet thisAlerts:
@chestertbauthorDec 15.2008 — Because this error only occurs intermitently, it's difficult for me to test this.

I have a question...

What happens when I set <base target='content'> in the top document, and then a link in the top document targets some other location <a href='cart.php' target='cart'>?

If I'm understanding what I've been reading in the W3org site, if I use <base target='content'>, then <a href='cart.php' target='cart'> will look for 'cart' within the 'content' frame.

Maybe the solution is to assign a unique identifier to each instance of the page when it opens.
Copy linkTweet thisAlerts:
@CharlesDec 16.2008 —  if I use <base target='content'>, then <a href='cart.php' target='cart'> will look for 'cart' within the 'content' frame.[/QUOTE]If &lt;base target='content'&gt; and &lt;a href='cart.php' target='cart'&gt; are in the same document then the local target attribute, local to the A element, will prevail and upon activating the link the browser should try to load "cart.php" in some window or frame named "cart". If you have multiple frames or windows with the same name then things are going to get weird. Perhaps it's time to re-think the project. Frames and spawned windows are icky anyway.
Copy linkTweet thisAlerts:
@chestertbauthorDec 16.2008 — Yeah. Thanks Charles. I think "icky" is a good way to describe it.

Thanks for everyone's contrubution. Much appreciated, and it's made me realise I need to go down the unique identifier route, which won't be too difficult.

If I may, though, here's a thought on the iframe issue...

In a web page that doesn't use iframes, each time a user clicks to access different content, the whole page re-loads, which is inneficient when only a small part of the page is to be changed. It diminishes the user experience by creating periods of time where his page blanks, and the duration of that blanking is governed by traffic, connection speed, processor speed, and available memory, all of which are beyond my control.

In a iframe page, only the changing content re-loads. Everything else stays put, reducing bandwidth consumption and maintaining the top page for your visitor to look at.

The truth is, iframes work, and if they are so bad, then why did the creators of html create them in the first place? After all, they're in the W3 specification, aren't they? They're recognised by all useful browsers, aren't they? Even the creators of javascript enabled methods of acessing data or functions in one iframe from another. It's part of the design.

Why, then, are they so evil? Why does such prejudice exist against them?

I like iframes. I'm a big fan. In this project, in the absence of a simpler solution, I just need to make each instance unique so I can preserve the user experience while maintaining functionality.
Copy linkTweet thisAlerts:
@FangDec 16.2008 — Difficulties: referencing, bookmarking, SEO
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...