Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript & IFrame - Read content URL?

Posted on 2008-10-13
3
Medium Priority
?
1,217 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 1464 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

Industry Leaders: 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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

971 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