?
Solved

Name of page in use in any given frame

Posted on 2011-03-08
4
Medium Priority
?
200 Views
Last Modified: 2012-06-27
Hi,

Is there anyway I can find out the URL currently being displayed in any given frame on a page.

Any help appreciated.

0
Comment
Question by:optidoc
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Designbyonyx
ID: 35070185
Using Chrome, you can right click and select "View Frame Source".  When the source code loads, look at the URL... that's your frame page.

In firefox, you can right click -> This Frame -> View Frame Source
0
 

Author Comment

by:optidoc
ID: 35164222
Sorry, should have been more specific -  I was looking for a way of doing it using javascript from within the page, apologies.
0
 
LVL 14

Accepted Solution

by:
Designbyonyx earned 2000 total points
ID: 35165892
Ah, I see.

So you should always be able to get the original SRC of the iframe... meaning the page that was loaded when the iframe was created.  Also, if you change the SRC using javascript, you should be able to get that value.

However, if the user clicks a link INSIDE the iframe, I don't think you can get the new SRC unless the page is being hosted on your domain.  Does that make sense?  Here's an example:

<!-- Example when everything is SAME domain -->
<iframe id="myIFrame" src="some-page.html" />

<script>
// 1) If you change the SRC using javascript, then both of these will give you the current page
// 2) If the user clicks a link in the iframe, then you will have to use the "currentPage" variable
var originalPage = document.getElementById('myIFrame').src;
var currentPage = document.getElementById('myIFrame').contentWindow.location.href;
</script>

Open in new window



<!-- Example when iframe is on different domain -->
<iframe id="myIFrame" src="http://some-domain.com/some-page.html" />

<script>
// The "originalPage" will work, but will always give you the ORIGINAL page name
// If you change the SRC using javascript, the "originalPage" will show you the new URL
var originalPage = document.getElementById('myIFrame').src;

// The "currentPage" will not work for security reasons
// If the user clicks a link in the iframe... you are out of luck
var currentPage = document.getElementById('myIFrame').contentWindow.location.href;
</script>

Open in new window

0
 

Author Closing Comment

by:optidoc
ID: 37314839
Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

862 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