Solved

Javascript & IFrame - Read content URL?

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

frm.contentWindow.location.href

Open in new window

0
 
LVL 44

Expert Comment

by:scrathcyboy
Comment Utility
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
Comment Utility
Thank you !

 I spent days trying to figure this out
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now