473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

<iframe> problem

Hi!
I have created page which contains some menu buttons and <iframe> with
sub-page. Each menu action on the master web site should change content of
iframe (by changing src attribute). But how to detect when user has opened
subpage not in master's <iframe> ? Is it possible to obtain reference to
master's page from sub-page ? When I'm trying to do this using Page.Parent I
get null exception :(

Here's a piece of code
//master.aspx
<%@ Page language="c#" Codebehind="master.aspx.cs" ... %>
....
<form id="Form1" runat="server" method="post">
<iframe id="myIFrame" runat="server" src="subpage.aspx"></iframe>
<asp:Button id="btnStart" runat="server" Text="Button">
</form>
....

//master.aspx.cs
....
private void btnStart_Click(object sender, System.EventArgs e)
{
myIFrame.Attribures["src"] = some_url_address;
}
....

Thx,
Grzesiek

Nov 19 '05 #1
5 2243
As far as the Server is concerned, your page and your IFRAME are in
separate browsers. The frame content has no knowledge of its
container, and the container is never posted back and thus cannon even
redraw itself.

This is all solvable through client-side scripting, but it's not
trivial. I wouldn't recommend attempting it except as a last resort.

Basically, this sounds like an architecture issue. The only reason you
would want to use an IFRAME in the first place is if you knew you
wouldn't have to redraw anything else on the page. You're asking how
to redraw the rest of the page every time you flip out the IFRAME
source, which begs the question: why are you using IFRAMEs at all?
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #2
> Basically, this sounds like an architecture issue. The only reason you
would want to use an IFRAME in the first place is if you knew you
wouldn't have to redraw anything else on the page. That's right
You're asking how to redraw the rest of the page every time you flip
out the IFRAME source No, I just want to check whether sub page is being launched in
iframe or in standalone browser window. The reason is that
it is possible to navigate from sub page to master page, which
contains .... yes iframe with subapge, so it could casue page-cycle,
which wouldn't look nice ;)
which begs the question: why are you using IFRAMEs at all?

It isn't my idea:( I have to have work area and menu. The menu
shouldn't be changed. So because asp .net hasn't got support
for multiple frames I decided to use iframe. Another solution
is to use framesets, bu this requires heavy client-side scripting,
and I'm not advanced in this.

thanks,
Grzesiek
Nov 19 '05 #3

"Grzesiek" <grzechu83@NOSPAM_CUT_ME.gazeta.pl> wrote in message
news:dd**********@inews.gazeta.pl...
Hi!
I have created page which contains some menu buttons and <iframe> with
sub-page. Each menu action on the master web site should change content of
iframe (by changing src attribute). But how to detect when user has opened
subpage not in master's <iframe> ? Is it possible to obtain reference to
master's page from sub-page ? When I'm trying to do this using Page.Parent
I
get null exception :(

[snip]

Hi Grzesiek,

As far as I know, this needs to be done in javascript.

If you look on the MSDN site, they keep every page within the MSDN frameset.
So if you enter a url like :
http://msdn.microsoft.com/workshop/a...ties/top_1.asp
It will redirect you to
http://msdn.microsoft.com/library/de...ties/top_1.asp
If you look at the code on thier page, you will see the code to redirect.
(hint: search for "top == self").

The MSDN script just checks if you opened the page directly, but it doesn't
check if it was opened within an iframe on another site. If you are trying
to avoid this, you should look into window.top.location.href

I've included a small example of what window.top.location.href returns.

Good luck.
--
Regards,
John MacIntyre
http://www.johnmacintyre.ca
Specializing in; Database, Web-Applications, and Windows Software
The parent page with an iframe
-- p.htm --
<html>
<body>
<iframe src="c.htm" frameborder="yes"></iframe>
</body>
</html>
-------

The child page
-- c.htm --
<html>
<head>
<script language="javascript">
function body_onLoad()
{
lbl.innerText=window.top.location.href;
}
</script>
</head>
<body onload="body_onLoad();">
<label id="lbl">Not Set</label>
</body>
</html>
-------
Open the p.htm page & the c.htm pages seperately and see what url is
returned.


Nov 19 '05 #4
Ah. Then the Top frame never has to come into play at all. Just throw
a script into every page that needs to live on top that sniffs to
ensure that it is not inside a frame:

<script>
if (self != top)
{
top.location.href = location.href;
}
</script>

If a page with the above script ever finds itself inside an IFRAME or
FRAME, it will reload itself in the top position. That's the standard
fix for this issue.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #5
> <script>
if (self != top)
{
top.location.href = location.href;
}
</script>


How simple, but works fine for me!
Big Thx for help

Grzesiek
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: O.J. Tibi | last post by:
hi guys, i was wondering if you could help me with a small problem. i need to have an <iframe> to behave like a <div>, in such a manner that: 1) the <iframe> should have its own display space,...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
2
by: chaitatp | last post by:
Hi guys, I have posted a similar question before but this post has some different. The similar link is: ...
1
by: tilt | last post by:
Hello, I use an object element to replace the iframe element in ie, like this: <object id="x_obj" data="http://.../" type="text/html"> <iframe name="x_if" id="x_if"...
0
by: diver | last post by:
I was using an <iframe> to load a website within my .aspx page. When the user "logged out", I called a javascript break out function to breakout of the frame and load the appropriate page when...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.