Solved

Name of page in use in any given frame

Posted on 2011-03-08
4
190 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

762 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

8 Experts available now in Live!

Get 1:1 Help Now