Can I use js to fetch title of remote url?

R

Randell D.

Folks,

I know javascript has no local or server based access to the disk however I
was wondering if one can read a remote page and take its html <TITLE>
value...

My guess is no but thought I'd check/ask anyway...

Thanks,
randelld
 
N

N/A

You can always create an XML HTTP request object (assuming the remote PC has
MS XML installed) and use it to read in the contents of the remote page,
then parse it for the <TITLE> block...
 
L

Laurent Bugnion, GalaSoft

Hi,
Folks,

I know javascript has no local or server based access to the disk however I
was wondering if one can read a remote page and take its html <TITLE>
value...

My guess is no but thought I'd check/ask anyway...

Thanks,
randelld

You're mixing two things. While it's true that client-side JavaScript,
under normal security environment (i.e. executed in a browser from the
web and without special security settings) is unable to read from the
local disk, it has nothing to do with it's unability to extract other
pages' attributes. This is the so-called "same origin policy" which
prevents it to do so. In short, JavaScript can access pages originating
from the same domain only. Now, some browsers are more relaxed about
this than others, but to be on the safe side, you should accept that
this is impossible if both pages are not on the same domain.

If the pages are on the same domain, then you can read (and set, on
newer browsers) the document.title property.

HTH,

Laurent
 
R

Randell D.

Laurent Bugnion said:
Hi,


You're mixing two things. While it's true that client-side JavaScript,
under normal security environment (i.e. executed in a browser from the
web and without special security settings) is unable to read from the
local disk, it has nothing to do with it's unability to extract other
pages' attributes. This is the so-called "same origin policy" which
prevents it to do so. In short, JavaScript can access pages originating
from the same domain only. Now, some browsers are more relaxed about
this than others, but to be on the safe side, you should accept that
this is impossible if both pages are not on the same domain.

If the pages are on the same domain, then you can read (and set, on
newer browsers) the document.title property.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Thanks for that... I am writing a publication type system in PHP and offer
the user to option of entering optional links related to the article they
are entering... I know I could have PHP fetch the page title of the remote
page but I would have prefered to have the client PC to perform the fetch -
If I am to understand you above, I would not (legally) be able to use
javascript to read the title of the link since it will not be on the local
domain... I'll stick with PHP for the chore.

Thanks for the info though - I hadn't realised that there was the
opportunity to read a same domain page using javascript.

randelld
 
R

Randell D.

N/A said:
You can always create an XML HTTP request object (assuming the remote PC has
MS XML installed) and use it to read in the contents of the remote page,
then parse it for the <TITLE> block...



however

Thanks for the reply but XML may not always be available on the remote
system so its not an option I can use - I am programming in PHP serverside
so it will be easier for me to have it (PHP) do the work for me.

randelld
 
R

Randell D.

N/A said:
so why are you poting in a javascript newsgroup? use php to do it....

My preference was for the client, not the server to perform the fetch...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top