Solved

Name of page in use in any given frame

Posted on 2011-03-08
4
194 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
[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
  • 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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Ouput in html in powershell 2 32
Google Tag Manager - Add Trigger Using Div class 22 62
Search Item in Table 2 43
send email part1 9 41
This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

730 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