Solved

Javascript & IFrame - Read content URL?

Posted on 2008-10-13
3
1,212 Views
Last Modified: 2013-11-19
Hello:

I am working with Javascript and IFrames.

I have a single web page with a single IFrame. There are several links that can be clicked to display content within the IFrame.

What I would like to do is that if a user clicks a link it will display the IFrame content. If the user clicks the same link again and the IFrame is already displayed, it will hide the frame. However, if the user clicks a different link the content will change and the frame will remain being displayed.

I have already completed this task, however, I had to change some code in order for the browsers 'back' button to function properly.

Here is the code:

function Hide(frameid) {

      var frm = document.getElementById(frameid);
      var url = frm.src;

      if(frm.style.display=='none') {
            frm.style.display='block';          
            frm.contentWindow.location.replace('testpage1.html');                    
      } else {            
            if(ulr=='testpage1.html') {
                     frm.style.display='none';
            } else {
                   frm.style.display='block';          
                      frm.contentWindow.location.replace('testpage1.html');  
               }
      }
      
etc...

}

The problem is that i have to use:

" fmr.contentWindow.location.replace('testpage1.html'); "

 instead of just

" frm.src = 'testpage1.html';

The reason being is that I want the browsers 'back' button to not navigate the pages within the IFrame.
If I try to evaluate frm.src after using the replace feature it will return null. For some reason I am unable to evaluate the frames src at all after using the replace feature. This being so it is preventing me from knowing what content is being displayed.

Any suggestions would be appreciated.

Thanks
0
Comment
Question by:frosty5656
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
sh0e earned 366 total points
ID: 22708702

frm.contentWindow.location.href

Open in new window

0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22716114
without putting javascript code into each page going into the iframe, I am not sure you will be able to control the back browser button function.  IE specifically doesn't treat a page refresh like a new link navigated to, so it only puts one occurrence of that page into the back history, not repeated occurrences one after the other.  THerefore the back button usually only gives the first access to a link, and if the display was gone, the iframe has lost focus, so the property could be null.  I'm not certain you will solve this back button issue.
0
 

Author Closing Comment

by:frosty5656
ID: 31505744
Thank you !

 I spent days trying to figure this out
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question