Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'Capture'

$("#test_point_geck_info")
  .html("<div id='img_1' class='img_1'>" +
     "<img src = " + ROOT_PATH + 
     "/assets/Capture.PNG onclick=PopImage(" + ROOT_PATH + 
     "/assets/Capture.PNG,'xyz')" +
     " style='cursor:pointer;' class=thumbnail width='100' height='100'></div>");

Results following on the browser:

<img src="/assets/Capture.PNG" onclick="PopImage(/assets/Capture.PNG,'xyz')" style="cursor:pointer;" class="thumbnail" width="100" height="100">

function that am calling :

function PopImage(imagesrc,caption) {
var PopupImageContainer = new Image();
PopupImageContainer.src = PopupImageSRC;
setTimeout("PopupImageDisplay()",loadDelay);

}
like image 931
Vinay Avatar asked Mar 24 '23 08:03

Vinay


2 Answers

/assets/Capture.PNG is interpreted as a regex literal (for assets) with Capture.PNG as flags - which are invalid. You wanted a string: '/assets/Capture.PNG'.

Anyway, you shouldn't use inline event handler attributes - especially when you already have jQuery available. Better:

$("#test_point_geck_info").html('<div id="img_1" class="img_1">' +
'<img src = " + ROOT_PATH + "/assets/Capture.PNG" title="xyz" ' +
'class="thumbnail" width="100" height="100"></div>').find("img").click(PopImage);
function PopImage(e) {
    var imagesrc = this.src,
        caption = this.title;
    var PopupImageContainer = new Image();
    PopupImageContainer.src = PopupImageSRC;
    PopupImageContainer.onload = function() {
        PopupImageDisplay(PopupImageContainer, PopupImageCaption, PopupImageSRC);
    };
}
.thumbnail {
    cursor: pointer;
}
like image 126
Bergi Avatar answered Apr 25 '23 09:04

Bergi


It occurred for me when incorrectly put some codes between javascript

like image 32
Ebrahim Avatar answered Apr 25 '23 10:04

Ebrahim