I have a function in JavaScript something like
function continents(post_id,continent,countries){
location.href="/serv/continent.php?param="+post_id+"&"+continent+"/"+countries;
}
and then I have a anchor tag in my php page
<a href="javascript: void(0)" onclick="continents('<?php echo $row['sno']; ?>','<?php echo $url_con_name; ?>','<?php echo $url_contries; ?>')" >
<div>some date here </div>
</a>
Now the link is working fine but when I right click on that link I don't find open link in new tab and open link in new window .
How can I solve this without removing the function.
There is no href attribute in your a
tag, therefore there is no link to open.
The fix is to put a proper URL in your href attribute.
Since you are using jQuery, you likely shouldn't be using onclick attributes anyways.
Do something like this:
<a href="http://example.com/proper/link" id="myLink">
Then attach the JS logic via jQuery:
$('#myLink').click(function(e){
e.preventDefault()
// this will prevent the link from loading the
// href value upon click, but still leave it
// accessible to right-click contextual menu.
the rest of your JS logic here...
})
Add href="#"
and onclick event has return false;
Try
<a href="#" onclick="continents('<?php echo $row['sno']; ?>','<?php echo $url_con_name; ?>','<?php echo $url_contries; ?>'); return false;" >
<div>some date here </div></a>
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.