By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

Can I use js to fetch title of remote url?

P: n/a

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
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

Randell D. wrote:
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
--
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

Jul 20 '05 #2

P: n/a
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...

"Randell D." <yo**************************@yahoo.com> wrote in message
news:AX***********************@news3.calgary.shaw. ca...

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

Jul 20 '05 #3

P: n/a

"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3F1246CB.1020604@bluewin_NO_SPAM.ch...
Hi,

Randell D. wrote:
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
--
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
Jul 20 '05 #4

P: n/a

"N/A" <no*@here.com> wrote in message
news:jE****************@news-server.bigpond.net.au...
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...

"Randell D." <yo**************************@yahoo.com> wrote in message
news:AX***********************@news3.calgary.shaw. ca...

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



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
Jul 20 '05 #5

P: n/a
N/A
so why are you poting in a javascript newsgroup? use php to do it....
"Randell D." <yo**************************@yahoo.com> wrote in message
news:x2***********************@news3.calgary.shaw. ca...

"N/A" <no*@here.com> wrote in message
news:jE****************@news-server.bigpond.net.au...
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...

"Randell D." <yo**************************@yahoo.com> wrote in message
news:AX***********************@news3.calgary.shaw. ca...

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



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

Jul 20 '05 #6

P: n/a

"N/A" <no*@here.com> wrote in message
news:GM*****************@news-server.bigpond.net.au...
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...
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.