Get Page Title (RegExp Q) 
Author Message
 Get Page Title (RegExp Q)

I have found the following script (I have modified it slightly) for getting
a page title from a string (from a webpage) at
http://www.*-*-*.com/

function getTitle(s) {
 var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
 if(objReg.exec(s)!=null){
  if(RegExp.lastParen=="") return "Untitled"
  return RegExp.lastParen;
 } else {
  return 'undefined';
 }

Quote:
}

However it does not work if the title is on several lines.
I want the function to return 'Page Title' for both (1) and (2)
(1)
<title lang=en>
Page
Title
</title>
(2)
<title>Page Title</title>


Sun, 29 Aug 2004 23:11:41 GMT  
 Get Page Title (RegExp Q)
var objReg = /<title.*?>\n*([\s\S]*)\n*<\/title>/gi;

--
The trouble with life in the fast lane is that you get to the other end in an
awful hurry. -John Jensen

=-=-=
Steve
-=-=-


Quote:
> I have found the following script (I have modified it slightly) for getting
> a page title from a string (from a webpage) at
> http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp/971.asp

> function getTitle(s) {
>  var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
>  if(objReg.exec(s)!=null){
>   if(RegExp.lastParen=="") return "Untitled"
>   return RegExp.lastParen;
>  } else {
>   return 'undefined';
>  }
> }

> However it does not work if the title is on several lines.
> I want the function to return 'Page Title' for both (1) and (2)
> (1)
> <title lang=en>
> Page
> Title
> </title>
> (2)
> <title>Page Title</title>



Mon, 30 Aug 2004 02:44:39 GMT  
 Get Page Title (RegExp Q)
I am confused, why wouldn't you just use document.title??
Sorry for the ignorance.

Confused

Quote:
>-----Original Message-----
>I have found the following script (I have modified it

slightly) for getting
Quote:
>a page title from a string (from a webpage) at
>http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp/971.asp

>function getTitle(s) {
> var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
> if(objReg.exec(s)!=null){
>  if(RegExp.lastParen=="") return "Untitled"
>  return RegExp.lastParen;
> } else {
>  return 'undefined';
> }
>}

>However it does not work if the title is on several lines.
>I want the function to return 'Page Title' for both (1)
and (2)
>(1)
><title lang=en>
>Page
>Title
></title>
>(2)
><title>Page Title</title>

>.



Mon, 30 Aug 2004 03:19:13 GMT  
 Get Page Title (RegExp Q)
Because this would not be done using the browser, but using a standalone js
file.
s in getTitle(s) would be the result of file access via the FileSystemObject
and the TextStream Object (there are articles on the web on doing this). The
function will be performed on more than one file.


Quote:
> I am confused, why wouldn't you just use document.title??
> Sorry for the ignorance.

> Confused

> >-----Original Message-----
> >I have found the following script (I have modified it
> slightly) for getting
> >a page title from a string (from a webpage) at
> >http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp
> /971.asp

> >function getTitle(s) {
> > var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
> > if(objReg.exec(s)!=null){
> >  if(RegExp.lastParen=="") return "Untitled"
> >  return RegExp.lastParen;
> > } else {
> >  return 'undefined';
> > }
> >}

> >However it does not work if the title is on several lines.
> >I want the function to return 'Page Title' for both (1)
> and (2)
> >(1)
> ><title lang=en>
> >Page
> >Title
> ></title>
> >(2)
> ><title>Page Title</title>

> >.



Mon, 30 Aug 2004 17:28:56 GMT  
 Get Page Title (RegExp Q)
Thanks, that worked


Quote:
> var objReg = /<title.*?>\n*([\s\S]*)\n*<\/title>/gi;

> --
> The trouble with life in the fast lane is that you get to the other end in
an
> awful hurry. -John Jensen

> =-=-=
> Steve
> -=-=-



> > I have found the following script (I have modified it slightly) for
getting
> > a page title from a string (from a webpage) at
> > http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp/971.asp

> > function getTitle(s) {
> >  var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
> >  if(objReg.exec(s)!=null){
> >   if(RegExp.lastParen=="") return "Untitled"
> >   return RegExp.lastParen;
> >  } else {
> >   return 'undefined';
> >  }
> > }

> > However it does not work if the title is on several lines.
> > I want the function to return 'Page Title' for both (1) and (2)
> > (1)
> > <title lang=en>
> > Page
> > Title
> > </title>
> > (2)
> > <title>Page Title</title>



Mon, 30 Aug 2004 17:44:06 GMT  
 Get Page Title (RegExp Q)
Oh, ok. I see. Sorry about that. I was just under the
impression that it was for the web. Thanks.

WasConfused

Quote:
>-----Original Message-----
>Because this would not be done using the browser, but

using a standalone js
Quote:
>file.
>s in getTitle(s) would be the result of file access via

the FileSystemObject
Quote:
>and the TextStream Object (there are articles on the web
on doing this). The
>function will be performed on more than one file.


message

>> I am confused, why wouldn't you just use
document.title??
>> Sorry for the ignorance.

>> Confused

>> >-----Original Message-----
>> >I have found the following script (I have modified it
>> slightly) for getting
>> >a page title from a string (from a webpage) at

>http://www.infinitemonkeys.ws/infinitemonkeys/articles/asp
>> /971.asp

>> >function getTitle(s) {
>> > var objReg = /<title.*>[\n]*(.*)[\n]*<\/title>/gi;
>> > if(objReg.exec(s)!=null){
>> >  if(RegExp.lastParen=="") return "Untitled"
>> >  return RegExp.lastParen;
>> > } else {
>> >  return 'undefined';
>> > }
>> >}

>> >However it does not work if the title is on several
lines.
>> >I want the function to return 'Page Title' for both (1)
>> and (2)
>> >(1)
>> ><title lang=en>
>> >Page
>> >Title
>> ></title>
>> >(2)
>> ><title>Page Title</title>

>> >.

>.



Mon, 30 Aug 2004 23:44:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Getting program titles and versions - Another Newbie with a question

2. Getting freaking nuts here! Error 8002801d with RegExp

3. Getting freaking nuts here! Error 8002801d with RegExp

4. Getting freaking nuts here! Error 8002801d with RegExp

5. three Qs concerning ps and gv

6. adding a title to the title bar

7. Title only in title bar of msgbox

8. Change Title In Alert Box Title Bar ???

9. Changing the Title of the Web Page

10. html2ps only generates the page title

11. How to send title of page when submitting?

12. How to send title of page when submitting?

 

 
Powered by phpBB® Forum Software