I have a post type WebView
which I managed to bind with the service response as string but I have some links like related posts which have their ids. On clicking those links I want the user to go to that article. I have tried many solutions but its look like the JavaScript doesn't calls on click, it calls on load because my complete WebView is treated as string and if I concatenate it, it definitely doesn't remains a script.
Here is my complete WebView code and the screenshot attached is the link which is made in WebView.
I managed to make it work by concatenating the whole response in string. Below is the code which helped me achieve this
String getHtml()
{
var bodyStyle = "<!DOCTYPE html><html><head><style>body{height: 100%;}p{text-align:left;color:#191919;}filter{background-color:#191919;}a:link"
+ "{color:#2588B0; background-color:transparent}a:visited {color:#0099CC; background-color:transparent}"
+ "a:hover{color:#0099CC; background-color:transparent}a:ative{color:#0099CC; background-color:transparent}span{background-color: yellow;color: black}customRight{float: right}</style></head><body>";}
var refs = bodyStyle;
refs = refs + "<center><h4>" + response.Title + "<h4></center>";
if (response.Pc.Count > 0)
{
refs = refs + "<center><u>" + Pc +
"</a></u></center><br>";
}
if (string.IsNullOrWhiteSpace(response.Cn))
{
refs = refs + "<center>" + response.Cn + "</center><br>";
}
if (response.Judges.Count() > 0)
{
refs = refs + "<center> <strong>Coram:</strong> " + JudgesN + "</center><br>";
}
if (string.IsNullOrWhiteSpace(response.JGD.ToString()))
{
refs = refs + "<center> <strong>Decided On:</strong> " + response.JGD + "</center><br>";
}
if(string.IsNullOrWhiteSpace(response.AppealType) )
{
refs = refs + "<center> <strong>Appeal Type: </strong>" + response.AppealType + "</center><br>";
}
if (response.Appellants != null)
{
refs = refs + "<left><b>" + apeal + "</b></left>";
refs = refs + "<customRight>apeal</customRight><br>";
}
refs = refs + "<center>VERSUS</center>";
if (response.Respondants != null)
{
refs = refs + "<left><b>" + resp + "</b></left>";
refs = refs + "<customRight>resps</customRight><br><br>";
}
if (string.IsNullOrWhiteSpace(response.FinalVr))
{
refs = refs + "<center> <strong>Final:</strong> " + response.FinalVr + "</center><br>";
}
if (string.IsNullOrWhiteSpace(response.note))
{
refs = refs + "<p> <strong>Note:</strong><br/> " + response.Headnote.ToLowerInvariant() + "</p><br>";
}
if(response.Refs != null)
{
refs = refs + "<left><b>Refered Jdgmts: </b></left><br>";
foreach(var obj in response.Refs)
{
if(obj.Jid == null) {
refs = refs + "<p style='font-size:13px;'>"
+ obj.Title
+"</p>";
}
else
{
refs = refs + "<p style='font-size:13px;'>" + "<a href=\""
+ obj.Jid
+ "\" target=\"_blank\" onClick=\"(function(e){alert('e is here'); "+ loadJt(obj.Jid);+"return false;})(); return false;\">"
+ obj.Title
+ "</a>"
+ "</p>";
}
jdgmt = jdgmt.Replace("^^^", "<br/><br/>");
jdgmt = jdgmt.Replace("<SPARA>", "<p>");
jdgmt = jdgmt.Replace("</SPARA>", "</p>");
refs = refs + jdgmt;
refs = refs + "</body></html>";
return refs;
}
data.Source = new HtmlWebViewSource { Html = getHtml(), BaseUrl="http://url.com/", BindingContext = response };
Here is my LoadJt Function
string loadJt(string jjid)
{
loadJmt(jid);// invokes the constructor and updates my VM too.
return jid;
}
Below how links are displaying