Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Need help in doing iframe

views
     
TSSkyW
post Feb 27 2010, 08:08 PM, updated 16y ago

New Member
*
Junior Member
44 posts

Joined: Dec 2007
Recently, I am working on a club website. In the website, I am using the iframe from http://www.dyn-web.com/tutorials/iframes/.

The whole thing may sound complicated, but I hope sifus will try to understand what I mean.

Attached Image

Let's say now I have two pages: the first page is main page, the second page is equipments page. In the main page, I choose one of the equipment (let's say rope) under "Equipment" at the dropdown menu. So, it will link to the equipment page.

In the second page, I include all types of equipments at the submenu part (refer to the attachment picture). So when user click on one of the equipment, the description of the selected equipment will appear in the content part, where the iframe locates.

Now, here's the problem. Let's say both of the pages have different pictures at the image part. When user selects one of the equipment from the dropdown menu in the main page, the equipment page, which contains a different picture and the descriptions of the selected equipment, will appear. In another word, the equipment page is a fixed template, only that the image part and content part are varying. So, what shall I do so that when user clicks on the equipment from the dropdown menu in the main page, it will display the exact descriptions of the equipment in the iframe at content part?

I have no problem to change the content part when user clicks on one of the equipments at submenu part. The problem arises when linking the main page with the equipment page.

Please enlighten me. Thank you.
puaka_astro
post Feb 27 2010, 09:16 PM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


hmm.. try this

1. your image iframe named 'image_frame - <iframe name"image_frame"......
2. content iframe named - content_frame
3. link is in submenu iframe
CODE

[B]this is inside submenu[/B]
<a href="http://forum.lowyat.net/topic/1339427" onclick="changeContent('image_frame', 'http://www.google.com.my/logos/olympics10-sskating-hp.png');" target="content_frame">Link 1</a>

<script>
function changeContent(targetFrame, content) {
     top.frames[targetFrame].location.href = content;
}
</script>

TSSkyW
post Feb 27 2010, 11:10 PM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
QUOTE(puaka_astro @ Feb 27 2010, 09:16 PM)
hmm.. try this

1. your image iframe named 'image_frame - <iframe name"image_frame"......
2. content iframe named - content_frame
3. link is in submenu iframe
CODE

[B]this is inside submenu[/B]
<a href="http://forum.lowyat.net/topic/1339427" onclick="changeContent('image_frame', 'http://www.google.com.my/logos/olympics10-sskating-hp.png');" target="content_frame">Link 1</a>

<script>
function changeContent(targetFrame, content) {
     top.frames[targetFrame].location.href = content;
}
</script>

*
Perhaps my description is unclear, so you are misunderstanding me. Hmm, okay,let's explain in another way...

A B

Let's say A is a page(index.html), B is another page(equipment.html). In page A, it has a dropdown menu(I create it using the Spry Menu Bar in Dreamweaver). When I go to equipment, I can select from a list of equipments shown in the list. So, when I click on a particular equipment, it links me to page B WITH the descriptions about the selected equipment in content iframe. This is the problem that causes headache to me, but not the submenu because I have no problem to target the content to the content iframe when I click on any of the equipments in the submenu.

I hope you get what I mean.

Anyway, thank you for your help =).



Let me show you the code:
Iframe code
CODE
function dw_loadExternal(url, ifrmId, divId, bLoadMsg) {
   // defaults for iframe, display div
   ifrmId = ifrmId || 'buffer'; divId = divId || 'content';
   if ( window.frames[ifrmId] ) {
       // Could use location.replace method if you do not want back button to load previous iframe url
       //window.frames[ifrmId].location.replace(url);
       window.frames[ifrmId].location = url;
       // If you want the whole page to scroll to the top when new content is loaded
       //window.scrollTo(0,0);
       var lyr = document.getElementById? document.getElementById(divId): null;
       if ( lyr && bLoadMsg ) { // Option to display message while retrieving data
           lyr.innerHTML = '<p>Retrieving data. Please wait ...</p>';
           lyr.style.display = 'block';
       }
       return false;
   }
   return true; // other browsers follow link
}


// called onload of iframe
// displays body content of iframed doc in div
// checks for and invokes optional functions in both current document and iframed document
function dw_displayExternal(ifrmId, divId, fp) {
   // defaults for iframe, display div
   ifrmId = ifrmId || 'buffer'; divId = divId || 'content';
   
   var lyr = document.getElementById? document.getElementById(divId): null;
   if ( window.frames[ifrmId] && lyr ) {
       lyr.innerHTML = window.frames[ifrmId].document.body.innerHTML;
       lyr.style.display = 'block';

       // when using with script, may have some operations to coordinate
       // function in current doc or iframed doc (doOnIframedLoad)
       if ( typeof fp == 'function' ) {
           fp();
       }
       
       // Demonstrated in tooltip demo
       if ( typeof window.frames[ifrmId].doOnIframedLoad == 'function' ) {
           window.frames[ifrmId].doOnIframedLoad();
       }
   }
}


HTML part
CODE

/*CSS*/
#buffer { position:absolute; visibility:hidden; left:0; top:0 }
#content {
   margin: 2em 1em 2em 0;
   border: 0;
   padding:6px 8px;
   display:none; /* until loaded */
}

/*BODY*/
<a href="hidden2.html" onClick="return dw_loadExternal(this.href)">Testing</a>
<div id=content></div>
<iframe id="buffer" name="buffer" src="hidden1.html" onload="dw_displayExternal()"></iframe>

What shall I include for the link of each item in the dropdown menu so that page B will show the description of the clicked item in the content iframe?

This post has been edited by SkyW: Feb 27 2010, 11:34 PM
puaka_astro
post Feb 27 2010, 11:43 PM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


lol.. perhaps screenshots would help us(or maybe just me cause i dont get it smile.gif) understand better


Added on February 27, 2010, 11:54 pmsomething like this ?
CODE

onClick="return dw_loadExternal(this.href, 'your frame id here')"


This post has been edited by puaka_astro: Feb 27 2010, 11:54 PM
TSSkyW
post Feb 28 2010, 12:07 AM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
Main Page
Attached Image

Equipment Page
Attached Image

So basically equipment page is just a template for all the equipments. The varying part is at the content. Now, my problem is I don't know how to link the item in the dropdown menu in main page to the equipment page, which contains the descriptions of the previously clicked in the content part. sad.gif
puaka_astro
post Feb 28 2010, 12:57 AM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


so the drop load will load description inside that iframe ? can;t use my previous post eh ? you said you know how to load content into iframe, so just do so.. but the link you put in href must only show the desc text, e.g
in php
CODE

<a href="content.php?action=get_description&amp;id=1234" target="content_frame">



Added on February 28, 2010, 12:58 amor you can use ajax to load the text, your call

This post has been edited by puaka_astro: Feb 28 2010, 12:58 AM
TSSkyW
post Feb 28 2010, 01:27 AM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
QUOTE(puaka_astro @ Feb 28 2010, 12:57 AM)
so the drop load will load description inside that iframe ? can;t use my previous post eh ? you said you know how to load content into iframe, so just do so.. but the link you put in href must only show the desc text, e.g
in php
CODE

<a href="content.php?action=get_description&amp;id=1234" target="content_frame">



Added on February 28, 2010, 12:58 amor you can use ajax to load the text, your call
*
Hmm...so it can only be achieved by using php or asp?

I try something like this,but no luck. Techinically,this doesn't bring forward the information abt hidden2.html frm the main page to the equipment page,right?
CODE

<a href="equipment.html" onClick="return dw_loadExternal('hidden2.html')">Tent</a>


I'm not so good in Javascript, but I'm just using my common sense. Sorry if I have asked you any silly question.... smile.gif

This post has been edited by SkyW: Feb 28 2010, 01:28 AM
puaka_astro
post Feb 28 2010, 01:58 AM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


QUOTE
<a href="equipment.html" onClick="return dw_loadExternal('hidden2.html')">Tent</a>
if you want to target iframe, add 1 more param to that function

CODE

onClick="return dw_loadExternal('hidden2.html', 'YOUR IFRAME ID')".....



Added on February 28, 2010, 2:00 amone more thing.. its never silly to ask a question.. smile.gif

This post has been edited by puaka_astro: Feb 28 2010, 02:00 AM
TSSkyW
post Feb 28 2010, 10:19 AM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
I add 1 more param, but it's still the same. I mean that when it links from index.html to equipment.html, the params do not bring forward to equipment.html. So, basically, it just displays default equipment.html instead of having hidden2.html(let's say this is the content for tent) at the content iframe in equipment.html.

I just found a website on teaching on how to pass parameters from one page to another page using sth like www.example.com/index.html?desc=tent. I have altered the code, but it doesn't work. Can you help me to take a look at the code?

CODE

<FORM NAME="tpl">
<INPUT TYPE="hidden" NAME="strvalue">
</FORM>

<script LANGUAGE="javascript">
var locate = window.location
document.tpl.strvalue.value = locate
var desc = document.tpl.strvalue.value

function delineate(desc)
{
str1 = desc.lastIndexOf("=");
str2=desc.substring(str1+1, str1.length);
document.tpl.strvalue.value=str2;
}
</SCRIPT>

<iframe src="document.tpl.strvalue.value"></iframe>


So, let's say put a hyperlink www.example.com/equipment.html?desc=hidden1.html for "tent", it will link me to the equipment page. But i can't display the page in the iframe.

This post has been edited by SkyW: Feb 28 2010, 11:45 AM
puaka_astro
post Feb 28 2010, 05:48 PM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


i have absolutely no idea why its not working on your machine. here is my working code. note that for js functions were copied from your prev post

CODE

<div class="container">
<div class="span-24">
 <ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a class="MenuBarItemSubmenu" href="#">Item 3.1</a>
   <ul>
    <li><a href="http://forum.lowyat.net/topic/1339427" onclick="return dw_loadExternal('hidden2.html', 'content_frame');">Link 1</a></li>
   </ul>
  </li>
 </ul>
</div>
<div class="span-24">
 <iframe name="image_frame" src="image.html" class="span-24"></iframe>
</div>
<div class="span-8">
 <a href="hidden2.html" onClick="return dw_loadExternal(this.href, 'content_frame')">Testing</a>
 <div id=content></div>
 <iframe id="buffer" name="buffer" src="hidden1.html" onload="dw_displayExternal()"></iframe>
</div>
<div class="span-16 last">
 <iframe name="content_frame" id="content_frame" src="content.html" class="span-16"></iframe>
</div>
</div>

TSSkyW
post Feb 28 2010, 06:35 PM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
I'm using the similar code too. It also works perfectly on my machine, but...hmm...what shall I say? Haha.

Btw, do you understand what do the error messages mean?

QUOTE
1. Unsafe JavaScript attempt to access frame with URL chrome://chromewebdata/ from frame with URL file:///C:/Users/Sky/Desktop/d4oswd/equipment.html?desc=hidden1.html. Domains, protocols and ports must match.

2. file:///C:/Users/Sky/Desktop/d4oswd/dw_loader.js:44Uncaught TypeError: Cannot read property 'body' of undefined
puaka_astro
post Feb 28 2010, 10:16 PM

Casual
***
Junior Member
331 posts

Joined: Jun 2007
From: Isketambola


QUOTE
I'm using the similar code too. It also works perfectly on my machine, but...hmm...what shall I say? Haha.
Huh? i thought you're on localhost ?

for the exact description of the error, hopefully someone will write something here as i don't know much about theory stuffs, most probably related to file path..
TSSkyW
post Mar 1 2010, 06:31 PM

New Member
*
Junior Member
44 posts

Joined: Dec 2007
QUOTE(puaka_astro @ Feb 28 2010, 10:16 PM)
Huh? i thought you're on localhost ?

for the exact description of the error, hopefully someone will write something here as i don't know much about theory stuffs, most probably related to file path..
*
No, I'm not running on localhost. Since I'm not using other languages other than HTML, I thought i still can test the script outside the server?

Well, even though I tried this on localhost, the same thing appeared. Just that in the iframe, it stated that the page was not on the server. Sad sad.gif

I guess this may related to the cross-domain limitation, but my files are exactly at the same location. So I don't know why the iframe cannot load the page. When I use IE, it keeps showing page error at the status bar.

CODE

lyr.innerHTML = window.frames[ifrmId].document.body.innerHTML;


It keeps saying this line is having error. But when I change the iframe src to normal link (let's say hidden1.html), it can work perfectly. Just that when i change the iframe src to delineate(desc), the content cannot be loaded into the iframe. The same thing happens to when I change the src to www.google.com.

This post has been edited by SkyW: Mar 1 2010, 06:32 PM

 

Change to:
| Lo-Fi Version
0.0974sec    0.37    6 queries    GZIP Disabled
Time is now: 26th November 2025 - 03:10 AM