...
...
HtmlTextWriter write12 = new HtmlTextWriter(stringWriter);
...
...
write12.AddAttribute("href", myURL);
write12.WriteEncodedText("Click here to redirect");
...
...
- 上面的代码工作正常,但我想重定向并显示在弹出窗口中。
- 那么是否可以在点击链接时调用 javascript。
...
...
HtmlTextWriter write12 = new HtmlTextWriter(stringWriter);
...
...
write12.AddAttribute("href", myURL);
write12.WriteEncodedText("Click here to redirect");
...
...
只需添加一个onclick
属性:
write12.AddAttribute("onclick", "JsFunction()");
Javascript
function JsFunction()
{
// open popup
// ...
}
我是否正确理解您想在新窗口中打开链接?
您可以通过将目标设置为_blank
像这样,根本没有测试:
HtmlTextWriter write12 = new HtmlTextWriter(stringWriter);
write12.AddAttribute("href", myURL);
write12.AddAttribute("target", "_blank");
write12.WriteEncodedText("Click here to redirect");