简体   繁体   中英

Invalid regular expression flags parameter

I want to create some popup window using javascript. i pass the table content including the url from my codeigniter controller to my codeigniter view.

here is my code from my controller:

public function ajax_list_dokumen($id){
        if($this->session->userdata('logged_in')){
            $list = $this->m_agency->GetDataDokumen($id);
            $data = array();
            $no = $_POST['start'];
            foreach ($list as $lists) {
                $no++;
                $row = array();
                $row[] = $lists->id_dokumen_persyaratan;
                $row[] = $lists->jenis_dokumen;
                $row[] = '<a class="btn btn-primary" onclick="popup('.$lists->path_file.', Dokumen Preview, 800, 600)" ><i class="fa fa-eye"><i/></a>';
                $data[] = $row;
            }

            $output = array(
                            "draw" => $_POST['draw'],
                            "recordsTotal" => $this->m_agency->count_all_dokumen($id),
                            "recordsFiltered" => $this->m_agency->count_filtered_dokumen($id),
                            "data" => $data,
                    );
            //output to json format
            echo json_encode($output);
        }
    }

and here is my javascript:

function popup(url, title, w, h) {
    // Fixes dual-screen position                         Most browsers      Firefox
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
    var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
    base_url = "<?php echo base_url();?>";
    link = base_url+url;
    link = link.replace( /s+/gm, "-", link );
    var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
    var top = ((height / 2) - (h / 2)) + dualScreenTop;
    var newWindow = window.open(link, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

    // Puts focus on the newWindow
    if (window.focus) {
        newWindow.focus();
    }
}

bu i got Invalid regular expression flags error when i clicked the view button.

Javascript String.replace only takes 2 arguments. Change it like this:

link = link.replace( /s+/gm, "-");

If you want to replace all spaces with hyphen from the url that obtained from document path, you could do it like this:

link = base_url+url;
link = link.replace(/\s/gm, '-');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM