Solved

Javascript & IFrame - Read content URL?

Posted on 2008-10-13
3
1,208 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding to $.ajax() with type "POST" vs $.post() 4 27
Jquery 7 28
Why is my $_POST not going to results page 10 32
Calculating percentage 2 27
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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 embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

685 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