Google Answers Logo
View Question
 
Q: Web programing, javascript: Grabbing a URL from an iFrame on my Web site ( No Answer,   2 Comments )
Question  
Subject: Web programing, javascript: Grabbing a URL from an iFrame on my Web site
Category: Computers > Internet
Asked by: jec1000-ga
List Price: $25.00
Posted: 18 Jul 2006 13:03 PDT
Expires: 17 Aug 2006 13:03 PDT
Question ID: 747455
I have a web site that uses an iframe in it to allow the user  
to view other Web pages while he or she visits and uses some simple
apps on my site. I would like to use javascript within my site to grab
the website URL that the user is currently visiting (inside the
iframe), so as to be able to help the user remember which URL he last
visited.  However, when I try to get
the source using javascript it will always tell me the original source
of the iframe and not the page after the user has changed it by
navigating. Is there any way to do this using javascript or PHP? Thank
you.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Web programing, javascript: Grabbing a URL from an iFrame on my Web site
From: cnkunee-ga on 01 Aug 2006 04:33 PDT
 
hi,
it is an example below which works in ie6

<html>
<head>
<title>Test</title>
</head>
<script language=javascript>
var preObj
function getFrameSrc(obj)
{
if(preObj)document.getElementById('Show').innerHTML="Current
Location:"+preObj.href;
}

function SaveObj()
{
preObj=event.srcElement;
if(preObj && (preObj.tagName=='a'||
preObj.tagName=='A'))document.getElementById('Show').innerHTML='Loading...';

}
document.onclick=SaveObj
</script>
<body>
<ul>
<li>
<a href="://www.google.com" target="a">Google.Com</a></li>
<li>
<a href="http://www.yahoo.com" target="a">Yahoo.Com</a> </li>
<li>
<a href="http://www.kunee.com" target="a">Kunee.Com</a> </li>
<li>
<a href="http://www.china.com" target="a">China.Com</a> </li>
</ul>
<span ID=Show style=padding:5px;font-weight:bold></span>
<br/><br/><br/>
<iframe id=a name=a style="height:100%;width:100%;"
onload=getFrameSrc(this)></iframe>
</body>
</html>
Subject: Re: Web programing, javascript: Grabbing a URL from an iFrame on my Web site
From: cnkunee-ga on 01 Aug 2006 04:53 PDT
 
there is a bug .

try this
<html>
<head>
<title>Test</title>
</head>
<script language=javascript>
var preObj
function getFrameSrc(obj)
{
if(preObj)document.getElementById('Show').innerHTML="Current
Location:"+preObj.href;
}

function SaveObj()
{
var obj=event.srcElement;
if(obj && (obj.tagName=='a'|| obj.tagName=='A'))preObj=obj;
if(preObj && (preObj.tagName=='a'|| preObj.tagName=='A'))document.getElementById

('Show').innerHTML='Loading...';

}
document.onclick=SaveObj
</script>
<body>
<ul>
<li>
<a href="://www.google.com" target="a">Google.Com</a></li>
<li>
<a href="http://www.yahoo.com" target="a">Yahoo.Com</a> </li>
<li>
<a href="http://www.kunee.com" target="a">Kunee.Com</a> </li>
<li>
<a href="http://www.china.com" target="a">China.Com</a> </li>
</ul>
<span ID=Show style=padding:5px;font-weight:bold></span>
<br/><br/><br/>
<iframe id=a name=a style="height:100%;width:100%;"
onload=getFrameSrc(this)></iframe>
</body>
</html>

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy