Javascript function working strangely during the first call in CHROME ?
- by Sohil
HI all,
Below mentioned javascript code works fine in all browsers including chrome(from second call onwards).
function call(val){
url = window.location.href;
indexnum = url.lastIndexOf("/");
str = url.slice(indexnum+1);
window.location.href = url.replace(str, "sample.php?src_q=") + val;
}
I am calling this function on onclick of a link as below
<?php echo "<a href='#' onclick='javascript:call(\"$fieldvalue\");'>$fieldvalue</a>" ?>
Normal Behaviour : In all browser after clicking on the link new formed url is
url://localhost/mysite/sample.php?src_q=val
Strange Behaviour : When I click on the link for the first time in chrome value of variable val gets replaced by url and its value as follows
http://localhost/mysite/sample.php?src_q=http://localhost/mysite/val
This strange behaviour happens during the first click in chrome. From the second call onwards in the same tab, the value of variable val works fine and I get desired url.
I tried to google on it, but couldn't found any explanation.
Thanks in advance.