/    Sign up×
Community /Pin to ProfileBookmark

refering between pages

Hello

I have a code which displays a hidden div on the screen.
Upon a certain action (user clicking a link), I do the following in Javascript:
* I make that div visible.
*
I add an iframe to that div using innerHTML =

The javascript code that I have in the page that gets loaded in the IFrame need to be able to refer to the page that launched the IFrame.
The reason is that the javascript code in the target page will later remove that inner IFrame from the div (in the original page).

Here is the flow:
* User performs an action and an IFrame appears on the screen.
*
The user performs a second action and the IFrame dissapears.
I must use an IFrame, because the content that will be displayed in the IFrame is large and I don’t want to load it if it will not be needed (the user will not click the link). I use the IFrame to load it on demand.

How can I send a valid reference of the original page to the target page that gets loaded in the IFrame?

thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jlaincMay 18.2004 — If I understand you correctly, you are still in the same window and you wish to remove the I-Frame from the div tag? Rather than actually removing the I-Frame from the div tag, I would dynamically set the "src" attribute of the I-Frame within the div tag instead of inserting and removing the I-Frame alltogether. Then all you need to do is make the div's style tag "display:none" or "display:block" depending on the functionallity requested.

However, if you are refering to a different calling window, you may want to check out the window.opener properties such as one that I am using on a page of mine: "opener.location.reload(true);" This reloads the parent window from the child.

Hope this helps you somehow...
Copy linkTweet thisAlerts:
@davidklonskiauthorMay 18.2004 — Once I load a page inside an IFrame, I am using that page for reference. That means that I am not longer in the original page.

I need the ID of the original page to the page that is loaded in the IFrame.


Once I have the ID (or some other way to refer to the original page), then I can refer to any of the DIV elements in it from the page in the IFrame
Copy linkTweet thisAlerts:
@jlaincMay 18.2004 — Even though you are technically on a different "page" within the I-Frame, you are still in the same "window", and therefore should still be able to access anything in that window from your javascript in the I-Frame.

You may need to wrap the div tag in a form so that you can reference it from the I-Frame page something like below:

<form name="OriginalForm">

<div id="IFrameDiv" style="display:block">

<iframe id="MainFrame" src="SomePage.htm"></iframe>

</div>

</form>

Then you should be able to reference the I-Frame in your Javascript something like this:

function RemoveIFrame()

{

document.OriginalForm.IFrameDiv.style="display:none";

document.OriginalForm.MainFrame.src="";

}

Hope this helps, and if you know anything about Javascrip cookies, then please checkout my thread...
×

Success!

Help @davidklonski 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.18,
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,
)...