在做ACL的时候,想让没有权限的操作停止,并弹出一对话框提示权限不足(AJAX中已经实现)
但如果操作是类似
<a href="http://localhost/xxx/xxx.php" />xxxx</a>
这样的操作,就会直接跳转到这个页面(即使没有权限)
我想实现的是,页面依然是yyy.php,在没有权限的情况下,只是在yyy.php上弹出提示,而没有跳转动作
本来想说用重定向来实现,但如果原本yyy.php页面已经进行了数据的操作(比如修改了表单数据),这样重定向后修改的数据不就没了

解决方案 »

  1.   

    但这样也相当于重定向吧??原本的yyy.php页面里修改过的数据依然是还原了
      

  2.   

    怎么又是xxx,又是yyy的。什么意思。。
    function checkPermission()
    {
       if(没有权限)
       {
          exit("<script type='text/javascript'>alert('你Y没有权限!')</script>");
       }
    }checkPermission();
    do_you_job_here();
      

  3.   

    加上一个item属性,遍历页面的a标签即可但是每个链接,需要什么样的权限访问是个问题。还有这种方法,禁用js就没戏了
    <a href="http://www.baidu.com" item="admin">百度</a><br />
    <a href="http://www.google.com" item="user">谷歌</a><script>
    var link = document.getElementsByTagName('a');
    for(var i=0;i<link.length;i++)
    {
    if(link[i].getAttribute('item') == 'admin')
    {
    link[i].setAttribute('href', '#');
    }
    }
    </script>
      

  4.   

    <a href="http://localhost/xxx/xxx.php" />xxxx</a>
    ===================================
    lz该不会是在xxx.php里没做权限判定吧?
    或者这个<a>标签在用户没有权限的情况下,就不该出来。
      

  5.   

    你仅仅这样判断是不行的。
    即使你在页面前台判断了,不让其进入页面。
    那他直接在浏览器里输入地址,还是一样可以进入。
    你最好在PHP页面里加权限判断。
      

  6.   

    ACL部分之前是已经做好了
    如果没登录的话是直接跳转到登录页面,登录后,如果没权限则跳转到无权限提示的页面(echo "<h3>权限不足!</h3>";exit(); 类似这样的)试着修改无权限时的代码为
    echo "<script type=\"text/javascript\" language=\"javascript\">alert(\"权限不足!\")</script>";
    exit();
    但这样会变成在一个白页里弹出提示,而非我想要的在原本的页面里弹出提示
      

  7.   

    你试试,没有权限的,我加了alert提示
    <a href="http://www.baidu.com" item="admin">百度</a><br />
    <a href="http://www.google.com" item="user">谷歌</a><script>
    var link = document.getElementsByTagName('a');
    for(var i=0;i<link.length;i++)
    {
    if(link[i].getAttribute('item') == 'admin')
    {
    link[i].setAttribute('href', '#');
    try
    {
    link[i].attachEvent("onclick",fnClick);
    }
    catch(err)
    {
    link[i].addEventListener("click",fnClick, false);
    }
    }
    }
    function fnClick()
    {
    alert('没有权限');
    return false;
    }</script>
      

  8.   

    但这个是在前台判断啊...
    如果用户直接在地址栏里输入地址,那这判断就无效了啊...
    ACL是根据当前session里的用户ID和请求的地址来判断是否有权限,要和数据库进行交互的...
      

  9.   


    <html>
    <head>
    <script src="jquery.js"></script>
    </head>
    <script>
    jQuery(document).ready(function(){
    $("a.juirs").click(function(){//给需要权限的A加上class=juirs属性
    $.ajax({
       type: "POST",
       url: $(this).attr("href"),
       data: "ajax=1",
       success: function(msg){
     if(msg=="1"){
    return true;
     }else{
    alert("权限不足!");
    return false;
     }
       }
    }); 
    });
    });
    </script>
    <body>
    <a href="1.php" class="juirs">测试</a>
    </body>
    </html>1.php
    <?php
    $mod="user";
    $isJuirs = checkJuirs($mod);
    if(!$isJuirs){
    if($_POST['ajax']=="1"){
    die("0");
    }else{
    exit("权限不足!");
    }
    }else{
    if($_POST['ajax']=="1"){
    die("1");
    }
    }//*********************
    //php代码
    ?>
      

  10.   

    你执行这个代码看看
    <a href='http://topic.csdn.net/u/20100727/14/69ce5bc3-8685-4a56-860b-d8076d9f3b8a.html?18871'>test</a>
    <script>
    document.links[0].onclick=function kill(){alert('abcd');return false}
    </script>
      

  11.   

    奇怪了,你在顶楼怎么说的<a href="http://localhost/xxx/xxx.php" />xxxx</a>在yyy.php跳出提示,ajax实现了,但你不想要跳转过去判断也不喜欢那在当前页面js判断有何不可?????????????、、
    权限问题,在目标页面判断好了就行。前面有人说不应该出现链接,深表赞同根本你自己都搞不清想要什么
      

  12.   

    对不起,我没说清楚...
    我想说的是,如果当前页面中某些操作是以AJAX来实现的
    比如页面中某个按钮点击后显示一个DIV,这个DIV的数据必须有权限才可以访问
    这种情况下,我已经可以实现当无权限时,DIV层不会出现,而是直接提示无权限而另一种情况则是点击页面中的超链接,而这个超链接的作用不只是显示某个DIV而已,而是加载另一个页面(很正常的一个超链接 <a href="http://www.google.com">Google</a>)
    这种情况下,当我判断完用户没有权限时,弹出提示,但此时页面已经跳转了,虽然显示的是白页
      

  13.   

    那只是JS的问题。<html>
    <head>
    <script src="jquery.js"></script>
    </head>
    <script>
    jQuery(document).ready(function(){
        $("a.juirs").click(function(){//给需要权限的A加上class=juirs属性
    var thisHref = $(this).attr("href");
            $.ajax({
               type: "POST",
               url: thisHref,
               data: "ajax=1",
               success: function(msg){
                 if(msg=="1"){
                    location.replace(thisHref);
                 }else{
                    alert("权限不足!");
                 }
               }
            });
    return false;
        });
    });
    </script>
    <body>
    <a href="1.php" class="juirs">测试</a>
    </body>
    </html>
      

  14.   

    你不是已经通过AJAX验证过了吗?