1

On Codeigniter I have a code

HTML

//ROOTPATH is the constant Path and $recordId is coming from a loop.

<a href="#" onclick="windowRedirect('<?php echo ROOTPATH; ?>&action=deleteRecord&id=<?php echo $recordId; ?>','Are you sure you want to Delete');return false;">Delete</a>

Javascript

windowRedirect(url,msg)
{
  if(confirm(msg)) 
  { 
    window.location.href = url;
  }
  else
  {
   return false;
  }
}

I have written a simple javascript which will redirect url if user click on OK button but I am getting weird problem on Google chrome where this code is working perfectly on Mozila Firefox, IE 8/9 and Applae Safari. Can any one tell me how can I solve this Google Chrome Problem.

Though I have a doubt this script is probably not working because of '#' on the href field but I am not sure.

4

1 回答 1

1

这是一个工作示例:

<html>
</head>
<script>
function window_redirect(url,msg)
{

  if(confirm(msg))
  { 
    window.location = url;
  }
  else
  {
   return false;
  }

}
</script>
</head>
<body>

<a onclick="window_redirect('http://www.google.com','Are you sure you want to Delete');" href="#" >Delete</a>

</body>
</html>

您忘记在函数之前调用状态“函数”,如果您将 onclick 放在元素(链接)上,请始终将其放在 href="#" 之前,如果不是这种情况,某些浏览器将不会调用 onclick。

于 2012-09-27T18:56:16.110 回答