2016-07-28 111 views
0

我想在编辑屏幕上的保存按钮上使用杂货crud上的自定义重定向。我可以成功地使用重定向的URL片段如下面的例子:通过javascript杂货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添加到重定向URL的结束,但似乎无法得到它的工作。这是我到目前为止:

$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">' 
    ); 

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

回答

0

"+thehash"删除双引号。

串联运算符和一个变量不应该在生成的JavaScript中使用双引号。

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