Click to See Complete Forum and Search --> : Getting a url from an iframe
bigstyle
01-17-2003, 05:27 PM
Hi all,
first of all sorry if I make mistake but I am not english but I really need help.
I search for several days but I don t find.
I want to get an url that is in a iframe of a main page.(in php).
It seems to be possible but I dont manage.
I have tried to add something like that in my 'main page' :
<a href="javascript:alert(document.getElementById('monid').src);">link</a>
but it doesn t work.
Somebody has an idea please ?
:(
khalidali63
01-17-2003, 05:56 PM
your code should work, make sure the id "monid" exists in the iframe as n attribute
Khalid
bigstyle
01-18-2003, 05:48 AM
The id is good.
The problem with that code is that I get the url to call the iframe but not the url contained in the 'data' of the iframe.
I have no precised but the url of the iframe is not called directly.(It's not ssomething like : <iframe id="monid" src="http://www.google.com"></iframe>
(With that code,what you said works well)
The code for the iframe in my main page contains a url (with cgi)and it s this cgi page that is calling dynamically a page.
And I am searching to get the 'new' url.
I have to be able to read the 'data' of the page loaded in the iframe,I think.
To put in a nutchell,that is the code to call my iframe in my main page :
<iframe border=0 frameborder=0 height=960 width=400 name="iframe" id="monid" scrolling=yes src="http://www.site.com/cgi-bin/img.cgi?js=0">
<script language="JavaScript" src="http://www.site.com/cgi-bin/img.cgi?js=1"></script>
</iframe>
So the url called is decided by my cgi page,not by the iframe.
And if I used your code,I ve got the url of the cgi page not the url 'loaded' .
Thx
khalidali63
01-18-2003, 05:55 AM
Can you be a bit more scpecific or can you elaborate a bit more pls
Khalid
bigstyle
01-18-2003, 06:04 AM
I have edited my last post :)
khalidali63
01-18-2003, 06:34 AM
hnm interesting,I guess you can try
alert(IFrameName.document.location.href)
I'd like to see how it is handled this way
:-)
bigstyle
01-18-2003, 06:46 AM
thanks for your answer.
I have tested that but I ve got a javascript error : "acces refused" (line:1 ; car:1 ; code:0)
khalidali63
01-18-2003, 06:51 AM
there is one thing that can be your problem now,if the page being displayed is out of your domain then its a security propblem for your webserver,therefore it will not allow access to that page,but if the page is served from your webserver, then make sure your accessing the iframe with correct name
bigstyle
01-18-2003, 07:01 AM
Do you think it's only a problem of incorrect name for the iframe ?
I have tried one thing.
I have recorded my iframe and my main page in the same directory in my computer.
(My main page is like that :
<iframe border=0 frameborder=0 height=960 width=400 name="tap" scrolling=no src="img.html">
<script language="JavaScript" src="img.html"></script>
</iframe>
main page : <a href="javascript:alert(tap.document.location.href);">test</a>
and when I clik on 'test',the alert box show me the path of img.html in my computer(sth like : file:///c:/documents.../img.html),but not the url contained in my iframe.
So it seems to be the same result as the document.getElementById('monid').src but it gives the complete path.
khalidali63
01-18-2003, 07:11 AM
you need to run it on your server where you use CGI scripting to see what exactly is happening.
When it comes to CGI my knowledge is prety limited to what is causing an error.
khalidali63
01-18-2003, 07:12 AM
or better yet post a link that points to your test page.
bigstyle
01-18-2003, 07:40 AM
I have send you a private message with the url :)
khalidali63
01-18-2003, 07:47 AM
It looks like it is the out of domain problem,you wont be able to access the information
bigstyle
01-18-2003, 08:44 AM
Thx Dave,
I have tried as you said (<a href="javascript:alert(self.frames.tap.location.href);">link2</a> ) tap is the name of my iframe and I ve got the same result as what khalidali63 told me (alert(tap.document.location.href)) .
When i click on the link,I ve got the url of the html file called by the iframe but not the link contained in that file.(that is what s happened when i tried to make that locally in my computer;but if i tried directly 'on line',I ve got a "permission denied".)
khalidali63
01-18-2003, 09:06 AM
Yow will get permission denied or access refused from the browser if you try to acccess a reource out of your domain.
simply put,you can not do what your trying to do.
Khalid
bigstyle
01-18-2003, 01:00 PM
Well for example,I ve got a main page that is calling an iframe.The iframe is a html file named iframe.html for example.
In iframe.html,I ve got some texts and a url .
iframe.html can be like that :
<html><body>
some text
<a href="www.my.com">text</a>
</body></html>
What I want to get is www.my.com ; but if I tried what you told me (and khalidali63),I ve got the page of my iframe (so iframe.html)