Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:54

Is there support for opening a link in a REMOTE iframe?


Poster: f11at125
Dated: Tuesday September 19 2006 - 15:47:56 BST

Hello,

I have read and understand the Javascript process for linking to an Iframe ON THE SAME PARENT, but I am trying to write links that will open document.html inside an Iframe on a DIFFERENT PAGE... has anyone got any advice?

Just to re-cap: the menu on index.html needs to link to document.html that will open inside Iframe "harry" on subpage.html. Please don't send me to the script that would allow me to open the link in Iframe "harry" on index.html - that's not what I need to do!!

Thanks,

Doug


Poster: John
Dated: Tuesday September 19 2006 - 21:35:02 BST

Ruth has passed this up to the boss. Standby!

support for opening a link in a REMOTE iframe


Poster: f11at125
Dated: Tuesday September 19 2006 - 21:40:35 BST

Fantastic; thanks! I'm sure this isn't easy, but I bet it's possible. I found some scripts that handle it for straight html links, but the syntax of the script doesn't sit well inside the menu data JS. But if it would help to look at the logic of the script, let me know.

Thanks again for your help!

Cheers,
Doug


Poster: Ruth
Dated: Wednesday September 20 2006 - 1:22:22 BST

Hi,

What are the scripts that handle it in html? you can also use such things in the aI strings either by calling a clickfunction or by using url=javascript: whatever function.

My problem was the only thing I could find was a php setup and I know even less about php than I do js, and my js ability would fit in a thimble..if anyone sews anymore and even has one of those old fashioned thingees :)

Ruth


Poster: Andy
Dated: Wednesday September 20 2006 - 9:30:57 BST

Quote:
I found some scripts that handle it for straight html links


Can you send these over, I'm sure we can integrate them into the menu.

JS for opening remote iframe


Poster: f11at125
Dated: Wednesday September 20 2006 - 14:12:38 BST

Thanks;

I'll paste the script below. My Iframe is named "Iframe" - in the script that name must match the name of the iframe in question.

It requires that links be written as follows: <a href=iframecontentchild.html?framepage=remoteframeparent.html>link</a>. The menu doesn't seem to like the questionmark - I tried changing it to ASCII code (&#64), but that had no effect.

Thanks for your help!!

<script type="text/javascript">
function loadframe(){
if(window.location.replace)
window.frames.Iframe.location.replace(get('framepage'));
else
window.frames.Iframe.location.href=get('framepage');
}
function get(key_str) {
var query = window.location.search.substr(1);
var pairs = query.split("&");
for(var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("=");
if(unescape(pair[0]) == key_str)
return unescape(pair[1]);
}
return null;
}
if (location.search&&get('framepage')!=null)
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", loadframe, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", loadframe );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
loadframe();
};
}
else
window.onload = loadframe;
}
</script>

Remote Iframe


Poster: f11at125
Dated: Thursday September 28 2006 - 16:41:30 BST

Any findings on this - including "we find that it isn't possible?"

Thanks again,
Doug


Poster: Andy
Dated: Friday October 6 2006 - 11:44:39 BST

Hi,

The problem with the code is that it's not "Milonic DHTML Menu" related and everybody is too busy, I think, to help

Sorry about that


Poster: kevin3442
Dated: Friday October 6 2006 - 20:05:14 BST

Just a quick note... depending on what browsers you want to support, there may be a simple solution. With some browsers, you will find that simply using the iframe's name in the menu item's taget property will work. I.e.,

Code:
aI("text=Item Text;url=whatever.htm;target=iframeName;");


Try it with the different browsers you want to support and see if that works for you. If you need a more widely applicable solution, you'll have to open the urls with a javascript function. I might find time to help with that later.

Cheers,

Kevin


Poster: f11at125
Dated: Tuesday October 10 2006 - 15:11:37 BST

Hi Kevin,

The code you listed is for opening an html page inside an iframe on the same page; I am asking how to open an iframe on a remote page.

Andy,
the Javascript may not be DHTML-menu related, but the question (which remains unanswered): "Is it possible to use Milonic's DHTML menu to open a page in an iframe on anther page?" is certainly on-topic!

It's looking like the (fully acceptable) answer is "no, it is not possible." Please don't be reluctant to confirm that if it's the case; it won't make me love your product any less, I swear!

Thanks,

Doug


Poster: kevin3442
Dated: Tuesday October 10 2006 - 16:15:41 BST

f11at125 wrote:
Hi Kevin,

The code you listed is for opening an html page inside an iframe on the same page; I am asking how to open an iframe on a remote page.


Hi Doug,

Ah... but have you actually tried what I suggested? I understood the goal. The point I was trying to make was that the approach used to open a page in an iframe contained within the same window would also work to do what you want to do. In other words, The code I posted also works to open a page in an iframe in a different (remote) window. I have tried this myself and it works. But as I said earlier, it only works with some browsers (IE6, FF1.x, NS7... others). For this to work, you have to make sure to name your iframe using the name= attribute in the <iframe> tag. The value you assign to the iframe's name attribute is the same value you assign to the menu item's target property.

As I mentioned, there are other ways to do this that rely more heavily on javascript, which you could use with the menu's clickfunction property. If you trythe above and it doesn't work in all of the browsers that you want to support, then we can revisit the issue with a different approach.

If I may presume to expand on Andy's earlier point... To answer your question directly: No, the menu system does not supoprt that capability directly, beyond the use of the target property that I already mentioned. But yes, it is possible to use the menu to trigger additional code that does what you want. It's the "additional code" part that's the stickler. Since it outsideof the menuing system, it would typically be up to the end user to develop such code. Of course, as you've seen, people here will often assist with such an effort, if they have the know-how and the time.

Cheers,

Kevin


Poster: f11at125
Dated: Tuesday October 10 2006 - 16:50:31 BST

Oh yes, this was actually the very first thing I tried. What I found was that (in I.E. 6, anyway) it only worked if the page with the remote iframe was already open. Otherwise, it does not - and come to think of it, how could it possibly know where the remote frame is unless it was already cached in an open page? If it wasn't open, wouldn't explorer have to search the html of every page on the server to look for an iframe with the same name?

At any rate, just in case anyone has been following this discussion and looking for a solution, what I have done is save two versions of every page. One called "whatever.html," which is pure iframe content, and a second called "whateverframe.html," which is the outide frame with "whatever.html" loaded.

I link to "whateverframe.html" from the home page. once I'm inside the frame, I link to "whatever.html."

It creates clutter, but it works.

I wish I could show the example, but it's on our intranet.

Thanks everyone for helping me see if this was te best way to deal with the situation - it does seem to be.


Poster: kevin3442
Dated: Tuesday October 10 2006 - 18:23:06 BST

Hi Doug,

f11at125 wrote:
Oh yes, this was actually the very first thing I tried. What I found was that (in I.E. 6, anyway) it only worked if the page with the remote iframe was already open. ...


Well now... that's the first time you've mentioned that twist. I had assumed that the second page would already be open from some other process (like using a small window as a remote control for another main window). Yes, it only works if the target iframe already exists, which would require that the second window is already open. That does change things a little.

Quote:
At any rate, just in case anyone has been following this discussion and looking for a solution, what I have done is save two versions of every page. One called "whatever.html," which is pure iframe content, and a second called "whateverframe.html," which is the outide frame with "whatever.html" loaded.

I link to "whateverframe.html" from the home page. once I'm inside the frame, I link to "whatever.html."

It creates clutter, but it works.

I wish I could show the example, but it's on our intranet.

Thanks everyone for helping me see if this was te best way to deal with the situation - it does seem to be.


So, if I understand your current approach correctly, you have a separate frame page as a container for every content page. Is this because you are coding the iframe's src attribute to load each page?

A question for you, if you're still interested in a more automated solution. Would you prefer to have just one page with an iframe, where you specify what content page to load into the iframe? Less clutter that way. As I said, there are some approaches available, and I can help if you like.

Cheers,

Kevin


Poster: f11at125
Dated: Tuesday October 10 2006 - 18:30:30 BST

Thanks, Kevin-

You have it right. The thing is, I have a very different graphic approach to the home page (which segments information by department) than the sub pages. There may be a way for me to make multiple iframes all on one page and acheive the approach you are talking about. That would make it possible for me to repalce the elements that need to change based on what section the page falls under.

As I think about it, that may in fact be the simplest way to go.

Thanks!


Poster: kevin3442
Dated: Tuesday October 10 2006 - 19:58:38 BST

Hi Doug,

Something like this:

Make a container file -- we'll call it container.htm in this example -- that contains an iframe named "iframe1". This is the remote page/iframe that will be used to contain the intended content pages. The name of the page to load into the iframe is passed as a parameter to container.htm, in a url string (e.g., ?pagename.htm). container.htm defines a small javascript function, called loadIframe(), that parses the query string and loads the specified page into the into the iframe. The loadIframe() function is called from the onload event of the <body> tag in container.htm. The basic html in container.htm would look something like this:
Code:
<html>
<head>
<script   type="text/javascript">
function loadIframe()
{
  var urlStr;
  urlStr = location.search.slice(1);
  window.frames.iframe1.location = urlStr;
}
</script>
</head>
<body onload = "loadIframe()">
<h3>I am the "remote" container window with the iframe</h3>
<br>
<iframe name="iframe1" id="iframe1" frameborder="1" width="750" height="200" marginwidth="20" marginheight="10" scrolling="auto"> </iframe>
</body>
</html>

Note the definition of the loadIframe() function in the <head> of container.htm.

A menu item that opens container.htm in a separate window (if it is not already open) and passes the name of the page to load into the iframe would look something like this:
Code:
aI("text=Open test1.htm;target=container;url=container.htm?test1.htm;");

Two things to note: (1) The target property specifies a separate "container" window. If the conter window is not already open, it will be opened and then used. If the container window is already open, it will be used... another one will not be opened. (2) The url property is like so: url=container.htm?contentpage.htm;... where contentpage.htm is the name of the file you want to load into the iframe.

This way, you have only one page with an iframe to worry about, and any other page can be loaded into it. A similar approach could be taken for a container page with multiple iframes, but then you'd have to pass and parse a more complex query string including iframe names and page names (like ?frame1=page1.htm&frame2=page2.htm... etc). A little more complex, but do-able.

Hope that helps,

Kevin


Poster: Ruth
Dated: Wednesday February 21 2007 - 0:53:48 GMT

Hi Kevin,

Not sure if you're out of town, but how would you change the function to denote that you are loading iframe1 and iframe2?

Ruth