【问题标题】:Response.Redirect in HTMLHTML 中的 Response.Redirect
【发布时间】:2013-11-04 08:14:03
【问题描述】:

如何设置以下动态创建的 HTML 以重定向到 mypage.aspx

 Dim s As String = "        <div style=""float: left; width: 716px; height: 25px; "">"
s += "        <button type=""button"" id=""btnRedirect"" style=""float: right; width: 100px; font-size:12px;"" >Redirect</button>"
s += "        </div>"
 ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "temp1", "<script type='text/javascript'> $('" + s + "').dialog({width: 750, height: 400,resizable: false});</script>", False)

【问题讨论】:

    标签: html asp.net response.redirect


    【解决方案1】:

    使用on绑定到btnRedirect的点击事件。

    使用的跨浏览器重定向功能取自here:

    $('#btnRedirect').on('click',function(){
        _Redirect('mypage.aspx');
    });
    
    function _Redirect (url) {
        var ua        = navigator.userAgent.toLowerCase(),
            verOffset = ua.indexOf('msie') !== -1,
            version   = parseInt(ua.substr(4, 2), 10);
    
        // IE8 and lower
        if (verOffset && version < 9) {
            var link = document.createElement('a');
            link.href = url;
            document.body.appendChild(link);
            link.click();
        }
    
        // All other browsers
        else { window.location.href = url; }
    }
    

    【讨论】:

    • 您好,感谢您的回复。 btnRedirect 在 document.ready 中不可用,只有当用户按下特定按钮时才会触发背后的代码 - 然后弹出 div (上面有按钮) - 因此点击功能当前不会触发。链接按钮会更好吗?
    • 我已将点击绑定替换为 on 绑定。请参阅我的更新答案。
    猜你喜欢
    • 2012-02-09
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2014-10-17
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多