Easy Content Units usually use JavaScript to write the contents of the unit on your webpage, the trouble with this method is that search engines have JavaScript switched off when they visit your website. This means they never see the contents on the easy content unit, if you have a page with not much content but a nice unit, search engines will not see a lot when they visit. Using the ASP.NET (VB) code below converts the unit and then writes it out to the page before the page is rendered. Because its using ASP.Net, no matter who visits the page, the ASP code will always run, so the easy content unit will be visible to all search engines.
These are the name-space libraries needed.
<%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %>
I have put this in the page load section, so it only runs on page load. The way code works basically is by calling the unit and then stripping out all the JavaScript that writes to the page using document.write. This then leaves just the bare HTML which can then be written to the page along with any other HTML on the page.
Sub Page_Load(sender As Object, e As EventArgs)
'Variable declarations
Dim aSplit, i
Dim sOutput As String
Dim objResponse As WebResponse
'Read the ECU into a variable using a HTTP request
Dim objRequest As WebRequest = HttpWebRequest.Create("http://www.easycontentunits.com/js_unit.php?ecu_mid=1199&ecu_uid=50564")
'Get the response from the above request
objResponse = objRequest.GetResponse()
'Convert the response into a string using text streaming
Using sr As New StreamReader(objResponse.GetResponseStream())
strResult = sr.ReadToEnd()
sr.Close()
End Using
'We now need to get rid of all the JS code
'Get rid of document.write(unescape("
strResult = replace(strResult,"document.write(unescape(""","")
'Get rid of ")
strResult = replace(strResult,""")","")
'Get rid of );
strResult = replace(strResult,");","")
' next convert %hexdigits to the character
aSplit = Split(strResult, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For i = 0 to UBound(aSplit) - 1
sOutput = sOutput & Chr("&H" & Left(aSplit(i + 1), 2)) & Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
'Move finished hex conversion back to original var name
strResult = sOutput
End Sub
You put the code below on the page where you want the unit to appear.
<%Response.Write(strResult)%>