当前位置: 代码迷 >> JavaScript >> js 给a标签赋值链接 并onclick解决方案
  详细解决方案

js 给a标签赋值链接 并onclick解决方案

热度:159   发布时间:2013-10-11 14:52:39.0
js 给a标签赋值链接 并onclick

function clickwebcast(_a, id, ptitle, ptype) {

            var url = '*****' + '?' + Math.random();
            var user = '****';
            var u = '****';
            if (user == null || user.length == 0) {
                alert("登录后才能观看!");
                $(".gts_download").hide();
                $(".filter").show(); $(".gts_logindiv").css("visibility", "visible");
                scroll(0, 0);
                return false;
            } else {
                _a.setAttribute("onclick", '');
                $.get(
                    url,
                    { id: id, pagetitle: ptitle, pagetype: ptype },
                    function (data) {
                        if (data.OK) {
                            _a.href = data.Url + u;
                            _a.click("return true");
                        }
                    });
                return false
            }
        }

<a href="javascript:void(0);" onclick="return clickwebcast(this,Id,'PageTitle','***')" target="_blank">

原本要实现的功能是用户在页面上点击一个链接,然后去往另一个网站上观看视频,但是必须先登录。然后就有了上面的方法,但是现在出现了一个问题就是浏览器有时候会提示 已拦截xxx网站弹出的页面。
能不能规避一下不让浏览器出现这中提示?
或者你们有更好的方法?

------解决方案--------------------
用下面这个

    function clickwebcast(_a, id, ptitle, ptype) {

        var url = '*****' + '?' + Math.random();
        var user = '****';
        var u = '****';
        if (user == null 
------解决方案--------------------
 user.length == 0) {
            alert("登录后才能观看!");
            $(".gts_download").hide();
            $(".filter").show(); $(".gts_logindiv").css("visibility", "visible");
            scroll(0, 0);
            return false;
        } else {
            //_a.setAttribute("onclick", '');
            $.ajax({ type: 'GET', url: url, data: { id: id, pagetitle: ptitle, pagetype: ptype }
            ,async:false///////改为同步
            , success: function (data) {
                if (data.OK) {
  相关解决方案