473,748 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying link text as a hyperlink

Hey,

I don't really know much about ASP but I need some help modifying the way a
field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("N otes")%>

This is fine for displaying the text, but the text contains links which are
currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I
need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim
Jul 19 '05 #1
3 1906
<%
'// Example usage:

Dim strText
strText = InsertHyperlink s(rs.fields("Th is"))
Response.Write strText

'//

Function InsertHyperlink s(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd

strBuf = ""
iStart = 1
iEnd = 1
Set objRegExp = New RegExp

objRegExp.Patte rn = "\b(www|http|\S +@)\S+\b" ' Match URLs and emails
objRegExp.Ignor eCase = True ' Set case insensitivity.
objRegExp.Globa l = True ' Set global applicability.
Set objMatches = objRegExp.Execu te(inText)
For Each objMatch in objMatches
iEnd = objMatch.FirstI ndex
strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
If InStr(1, objMatch.Value, "@") Then
strBuf = strBuf & GetHref(objMatc h.Value, "EMAIL", "_BLANK")
Else
strBuf = strBuf & GetHref(objMatc h.Value, "WEB", "_BLANK")
End If
iStart = iEnd+objMatch.L ength+1
Next
strBuf = strBuf & Mid(inText, iStart)
InsertHyperlink s = strBuf
End Function
Function GetHref(url, urlType, Target)
Dim strBuf

strBuf = "<a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target=""" & _
Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If

GetHref = strBuf

End Function

%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
JimJones <No****@herenos pam.com> wrote in message
news:Cup9c.240$ 54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the way a field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("N otes")%>

This is fine for displaying the text, but the text contains links which are currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim

Jul 19 '05 #2
How would you do it in an normal html page? You'd do:
(Assuming you want the link text to be the url as well)

<a href="http://whatever">http://whatever</a>


So, how would you do it in asp? Substitute <%=variable%> in the places
where the url text would appear in the HTML if you were to manualy write it.

<%
sLink = rs.Fields.Item( "Notes").Va lue
%>

<a href="<%=sLink% >"><%=sLink%> </a>
Or use Steve's idea.

Ray at work
"JimJones" <No****@herenos pam.com> wrote in message
news:Cup9c.240$ 54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the way a field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("N otes")%>

This is fine for displaying the text, but the text contains links which are currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so basically I need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim

Jul 19 '05 #3
Thanks for both replies. I have it working now :-)

Jim

"Steven Burn" <nobody@PVT_i t-mate.co.uk> wrote in message
news:ON******** ******@TK2MSFTN GP11.phx.gbl...
<%
'// Example usage:

Dim strText
strText = InsertHyperlink s(rs.fields("Th is"))
Response.Write strText

'//

Function InsertHyperlink s(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd

strBuf = ""
iStart = 1
iEnd = 1
Set objRegExp = New RegExp

objRegExp.Patte rn = "\b(www|http|\S +@)\S+\b" ' Match URLs and emails
objRegExp.Ignor eCase = True ' Set case insensitivity.
objRegExp.Globa l = True ' Set global applicability. Set objMatches = objRegExp.Execu te(inText)
For Each objMatch in objMatches
iEnd = objMatch.FirstI ndex
strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)
If InStr(1, objMatch.Value, "@") Then
strBuf = strBuf & GetHref(objMatc h.Value, "EMAIL", "_BLANK")
Else
strBuf = strBuf & GetHref(objMatc h.Value, "WEB", "_BLANK")
End If
iStart = iEnd+objMatch.L ength+1
Next
strBuf = strBuf & Mid(inText, iStart)
InsertHyperlink s = strBuf
End Function
Function GetHref(url, urlType, Target)
Dim strBuf

strBuf = "<a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "<a href=""http://" & url & """ Target=""" & _
Target & """>" & url & "</a>"
Else
strBuf = "<a href=""" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "<a href=""mailto:" & url & """ Target=""" & _
Target & """>" & url & "</a>"
End If

GetHref = strBuf

End Function

%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
JimJones <No****@herenos pam.com> wrote in message
news:Cup9c.240$ 54.223@newsfe1-win...
Hey,

I don't really know much about ASP but I need some help modifying the
way a
field is currently displayed.

Currently the ASP code inside my page is simply:

<%=rs.Fields("N otes")%>

This is fine for displaying the text, but the text contains links which are
currently just being displayed as text. I'd like them to display as
hyperlinks that will open in new windows when clicked upon. so

basically I
need some ASP code to detect text starting with http:// or www.etc and
automatically make them into hyperlinks.

Could someone help me out with some code or point me to a webpage.

Thankyou.

Jim


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1511
by: Luis E Valencia | last post by:
I need a link on a datagrid, the link must have fields of the database Like this acciones.aspx?iddireccion=1&idindicador=4 Thanks
4
4832
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the value of the "id" field of that record as a URL parameter. Can someone tell me how to do this.
1
2643
by: tshad | last post by:
Is there some reason why the Hyperlink in a DataGrid will not show an image? I have a datagrid with the following: <asp:TemplateColumn visible="false" HeaderText="Skills"> <itemtemplate> <asp:HyperLink id="SkillsTestDate" imageURL="../images/checkmark.gif" visible="false" Text='<%# Container.DataItem("SkillsTestDate")%>' NavigateUrl='<%# "displayAppResumeEE2.aspx?JobID" & Container.DataItem("JobID") %>'
11
1442
by: Matt | last post by:
Why would this link not work on "Firefox 7.12 Version 1.07"? It works fine in IE? <a href='aac_product_home.asp?Category=product&Section='> <td width="145" <%if lcase(sCategory) = "product" then Response.Write "class='topnavcellactive'" else Response.Write "class='topnavcell'"%>>
4
9590
by: BLob | last post by:
Hi, I need to create an RTF document with PHP. Actually, I am using an already created RTF document which with strings like %var% that I replace with $var before sending the document. I need to create a link like http://www.example.com/id_content=125 but my problem is that in the document produced : I can read http://www.example.com/id_content=125 But if I click on the link it goes to
5
1785
by: kbrad | last post by:
I have an Access database set up with a number of text fields and a hyperlink field which references a different image per record. I am trying write ASP code to retrieve allt his data and images onto a web page. I have the data but the images are causing a problem. The code I am using is as follows: For the data: <TD><P><FONT COLOR="#000000"><% Response.Write rsRecordset("Fieldname") %></FONT></TD> This is fine. For the images:
4
3224
by: trichert | last post by:
Ok , developing a .aspx page with Visual Web Studio (the full page is at the bottom). Basically its a page that displays all my computers and the current logged on user pulling data from a live Altiris database. This works fine, i have added a feature with a link for me to click to run radmin against that computer so i can remote control it. The link shows properly when I hover over it "S:\apps\!drivers\WindowsETC\rview.bat PCNAME". ...
3
3127
by: William LaMartin | last post by:
I have a gridview (with no properties set) on an aspx page which I populate from an XML file with the code below. The data in the XML file looks like this <description>National Trust for Historic Preservation</description> <URL>http://www.nthp.org/</URL> <category>Architecture</category> Can anyone tell me why the other two columns are displayed, but the
0
1324
by: tshad | last post by:
I have set up an upload of doc and pdf files which works fine. If I open up the uploaded files in Word it looks exactly like the my originals. If I open up the files from my web page so that it opens up in IE, it displays ALMOST correct. On one of my pages I have a document that is Times Roman 10 and 11. Not bolded. But when I select my link which was an asp:Hyperlink object:
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.