开发者

Resolve URLs for ASP.NET in jQuery?

I would like to use "~/" and resolve on the client site.

For example, I w开发者_如何学JAVAould want to do this:

<a href="~/page.aspx">website link</a>
<img src="~/page.aspx" />

I would have my base URLs in ASP.NET like this:

<script type="text/javascript">
        var baseUrl = "<%= ResolveUrl("~/") %>";
</script>

Would I need a jQuery plugin for this or can this be a achieved with a chained command?


You could mass-replace the hrefs like this:

$('a').attr('href', function(index, oldValue) {
    return oldValue.replace('~/', baseUrl);
});

although the idea seems dangerous. What happens if javascript is disabled?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜