通过javascript的杂货Crud网址重定向

时间:2016-07-28 11:31:35

标签: javascript php codeigniter grocery-crud

我正在尝试在编辑屏幕上的保存按钮上使用杂货店上的自定义重定向。我可以使用URL片段成功重定向,如下例所示:

$the_catalogue_id = $this->uri->segment(count($this->uri->segments));    
$this->grocery_crud->set_lang_string('update_success_message',
             'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
             <script type="text/javascript">
              window.location = "'.base_url('catalogues/edit').'/'.$the_catalogue_id.'";
             </script>
             <div style="display:none">'
        );

我现在需要将window.location.hash添加到重定向网址的末尾,但似乎无法使其正常工作。这就是我到目前为止所做的:

$this->grocery_crud->set_lang_string('update_success_message',
         'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
         <script type="text/javascript">
         var thehash = window.location.hash
          window.location = "'.base_url('catalogues/edit').'/'.$the_catalogue_id.'"#"+thehash";
         </script>
         <div style="display:none">'
    );

如何将哈希变量添加到重定向网址的末尾?

1 个答案:

答案 0 :(得分:1)

"+thehash"删除双引号。

连接运算符和变量不应该在生成的javascript中用双引号。

   var thehash = window.location.hash;
   window.location = "'.base_url('catalogues/edit').'/'.$the_catalogue_id.'#"+thehash;