获取以前的URL并用作codeigniter中的后退按钮

时间:2014-10-10 05:59:31

标签: php codeigniter url

我真的很想知道我怎么能这样做,我有3个页面有相同的链接到1页,现在我想做的是有1个智能足够的按钮来获得3页中的哪一个被使用转到该页面并使用它,因为它的链接将返回上一页。

如果有人知道如何做到这一点,请帮助我摆脱这种混乱。发布一些代码如何在codeigniter中做到这一点。提前谢谢。

6 个答案:

答案 0 :(得分:7)

通过使用简单的javascript来实现之前的按钮,

<a href="javascript:window.history.go(-1);">Previous</a>

答案 1 :(得分:4)

加载url helper后,将current_url设置为隐藏字段,然后说“&#39; refer_from&#39;。

<input type="hidden" name="refer_from" value="<?php echo current_url(); ?>" />

使用Input Class获取并在锚链接

上设置此项
<a href="<?php echo $this->input->post('refer_from'); ?>">Previous</a>

注意:使用window.history.go(-1)将失败并抛出一个js错误,如果用户有些如何落地  直接在&#34; 1&#34;最后一页。在这种情况下,window.history将为空。

答案 2 :(得分:0)

在我的情况下,jquery back方法意味着window.history等,没有工作,我试过这个希望这可以帮助你们。点击这个方法。欢呼声

  function redirection()
        {
           <?php $send=$_SERVER['HTTP_REFERER'];?> 
            var redirect_to="<?php echo $send;?>";             
            window.location = redirect_to;

        }

答案 3 :(得分:0)

/ *使用jquery * /

在codeigniter项目中的后退按钮
<button type="button" class="btn btn-primary btn-sm"  id= "back">Back</button>

//后退按钮的JQuery

 <script type="text/javascript">
  $(document).ready(function(){
  $('#back').on('click', function(){
        <?php $send = $_SERVER['HTTP_REFERER'];?> 
        var redirect_to="<?php echo $send;?>";             
        window.location.href = redirect_to;
      });
   });
  </script>

答案 4 :(得分:0)

控制器中添加:

$data['back'] = $_SERVER['HTTP_REFERER'];

视图中添加按钮并链接到$back

答案 5 :(得分:0)

//to get previous url $_SERVER['HTTP_REFERER'];

<?php $send = $_SERVER['HTTP_REFERER'];?> 
var redirect_to="<?php echo $send;?>";    

//to redirected to this link
location.assign(redirect_to);

//you can pass static link also to redirected to this link
location.assign('facebook.com');