Solved

Name of page in use in any given frame

Posted on 2011-03-08
4
195 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

728 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