Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display document Title from ASP Function?

Status
Not open for further replies.

svagelis

Programmer
May 2, 2001
121
GR
Any way to display the document's title from my asp page?
Thanks in advance
 
Do you mean the <TITLE> for your HTML Page?
<%
yourAspTitleGoesHere = &quot;Dynamically Created Title&quot;
%>
<TITLE><%=yourAspTitleGoesHere%></TITLE> -----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
Well i ve figured out that there is no way to read document's title from ASP beacuse it's still running on server and not on browser yet.
The only way is to open current document as text and get from it whats inside <title> and </title> tags. Well this is the solution to this problem :

---- ASP Page
lTitle = GetTitle(Request.ServerVariables(&quot;SCRIPT_NAME&quot;))

----- ASP Functions

Public Function GetTitle(FileToRead)
whichfile=server.mappath(FileToRead)
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set thisfile = fs.OpenTextFile(whichfile, 1, False)
tempSTR=thisfile.readall

GetTitle = RequestTag(tempSTR,&quot;<title>&quot;,&quot;</title>&quot;)

thisfile.Close
set thisfile=nothing
set fs=nothing

End Function


Public Function RequestTag(strSource, strStartTag, strEndTag)

Dim StartPosition
Dim EndPosition

Dim strImageName

Dim StartSearch
Dim ImageLength
Dim i

StartSearch = 1

StartPosition = InStr(StartSearch, LCase(strSource), lcase(strStartTag))

EndPosition = InStr(StartPosition, LCase(strSource), lcase(strEndTag))


if StartPosition <> EndPosition And StartPosition <> 0 then
ImageLength = EndPosition - StartPosition

strImageName = Mid(strSource, StartPosition+len(strStartTag), ImageLength-len(strStartTag))

strImageName = Trim(strImageName)
end if

RequestTag = strImageName

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top