Request TITLE via ASP
July 21, 2007 4:54 PM Subscribe
ASP snippet to request contents of page's TITLE tag?
Someone gave me the following line of ASP that will write/call the URL of whatever web page it's on:
< %=Request.servervariables(" SERVER_NAME" ) & request.servervariables(url)%>
Can anyone please tell me what an equivalent line would be that will automatically pull the contents of the page's TITLE tag? Or do I need to go another route?
I want to make custom links that pass on page data, such as
Yes, I'm clearly clueless re: even the basics of ASP.>
Someone gave me the following line of ASP that will write/call the URL of whatever web page it's on:
< %=Request.servervariables(" SERVER_NAME" ) & request.servervariables(url)%>
Can anyone please tell me what an equivalent line would be that will automatically pull the contents of the page's TITLE tag? Or do I need to go another route?
I want to make custom links that pass on page data, such as
Yes, I'm clearly clueless re: even the basics of ASP.>
Best answer: You can't do it using a member of the ServerVariables collection -- that much I can tell you for sure (here's a list of all the methods available).
The only way I could think of to do it is have your TITLE tag be dynamically generated (and output using ASP, obviously), and then reference that same variable in your code. That probably doesn't help much, but it's about all I can think of since the ASP is processed as a precursor to the page being generated (and I therefore seriously doubt DOM objects are available at that point).
posted by Doofus Magoo at 6:20 PM on July 21, 2007
The only way I could think of to do it is have your TITLE tag be dynamically generated (and output using ASP, obviously), and then reference that same variable in your code. That probably doesn't help much, but it's about all I can think of since the ASP is processed as a precursor to the page being generated (and I therefore seriously doubt DOM objects are available at that point).
posted by Doofus Magoo at 6:20 PM on July 21, 2007
Best answer: No, there's really no equivalent thing. The server name and url are things the internet user is requesting from your server. The title is something that your server's page gives back to the user.
Since you are in control of these ASP pages, you (or really your server) will already know the page's title since it generates it in the html. For each page you could set the page's title to your own variable, and then use that in both the title tag and the link you are generating...
< % pagetitle="My page's title" %>
< html>
< title> < %=pagetitle %> < / title>
...
< a href='http://BLAHBLAH.com/submit?url=http://<%= request.servervariables(server_name) & request.servervariables(url)%>&title=< %=pagetitle%>' >>>>>>>>
posted by ghostmanonsecond at 6:29 PM on July 21, 2007
Since you are in control of these ASP pages, you (or really your server) will already know the page's title since it generates it in the html. For each page you could set the page's title to your own variable, and then use that in both the title tag and the link you are generating...
< % pagetitle="My page's title" %>
< html>
< title> < %=pagetitle %> < / title>
...
< a href='http://BLAHBLAH.com/submit?url=http://<%= request.servervariables(server_name) & request.servervariables(url)%>&title=< %=pagetitle%>' >>>>>>>>
posted by ghostmanonsecond at 6:29 PM on July 21, 2007
also, when you are including the title as a link, you'll need to wrap it in URLEncode. This translates characters likes spaces and periods and such into an equivalent that browsers will like better in a url. Those types of characters will break links.
< a href='...&title=<%= server.urlencode(pagetitle) %>'>
posted by ghostmanonsecond at 6:35 PM on July 21, 2007
< a href='...&title=<%= server.urlencode(pagetitle) %>'>
posted by ghostmanonsecond at 6:35 PM on July 21, 2007
This thread is closed to new comments.
I meant such as:
< a href='http://BLAHBLAH.com/submit?url=http://<%= Request.servervariables("SERVER_NAME") & Request.ServerVariables("URL")%>&title=??????' >
posted by MaxVonCretin at 4:57 PM on July 21, 2007