Reputation: 1506
I want to redirect my page by clicking on entire row.
For that my HTML table row is below which is created by javascript.
id = 1;
<tr onclick="document.location.href='http://localhost/emailc/emailCampaignEdit/"+id+"'">
<td><b>abc</b></td>
</tr>
before clicking on above code my browser's url is http://localhost/emailc
After click on code I want to redirect my page on this url http://localhost/emailc/emailCampaignEdit/1
Browsers url is changes perfectly on clicking. but browser is not redirecting to that url. If I refresh browser on that url then it works as I want.
I have tried this also for testing the syntax:
<tr onclick="document.location.href='http://www.google.com'">
<td><b>abc</b></td>
</tr>
It works perfectly, browser is completely redirecting to google page and I have also tested other redirecting codes likes window.location.href
or window.location.assign
or window.location
everything has same problem.
Upvotes: 4
Views: 3038
Reputation: 15836
<tr onclick="openWin('1')">
<td><b>abc</b></td>
</tr>
<script>
function openWin(id)
{
window.open("http://localhost/emailc/emailCampaignEdit/"+id)
}
</script>
can you try this out ?
Edit :
you may use this function :
location.reload(false);
which will reload page from server , instead reloading page from cache , right after the url changes
so you should use :
function openWin(id)
{
window.open("http://localhost/emailc/emailCampaignEdit/"+id,"_self");
location.reload(false);
}
Upvotes: 1
Reputation: 783
this should work, it works for me
var td = document.getElementsByTagName('td'), id = 1;
td[0].addEventListener('click', function(){location.assign('yourURL.php?id=' + id);}, false);
Note that document.location.href returns the URL of the page and does not redirect. Refer to http://www.w3schools.com/jsref/prop_loc_href.asp for more information.
Upvotes: 0
Reputation:
var id = 1;
document.write('<table>'+
'<tr onclick="document.location.href=\'http://localhost/emailc/emailCampaignEdit'+id+'\'">'+
'<td><b>abc</b></td>'+
'</tr></table>');
Please try above code
Upvotes: 0