Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using JavaScript to allow users to redirect to a url by clicking the rows on gridview. Currently, I am currently experiencing the following error (The resource cannot be found. A http 404 error.) Is there something I am missing in the code, to get this to work.

JavaScript
function SetMouseDown(element) {
    var r = confirm('Are you sure?');
    var url = window.location.pathname;
    var pathArray = url;
    var host = pathArray[1];
    var newHost = 'About.aspx';

    if (r == true) {
        window.open(host + newHost, 'name', 'width=200,height=200');
    }
    else {
        alert('it didnt work');
    }
    return false;
}


C#
protected void gvrecords_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         e.Row.Attributes["onmouseover"] = "javascript:SetMouseOver(this)";
         e.Row.Attributes["onmouseout"] = "javascript:SetMouseOut(this)";
         e.Row.Attributes["onmousedown"] = "javascript:SetMouseDown(this)";
     }


Many thanks for your help and time.
Posted
Comments
[no name] 17-Jan-14 11:07am    
Did you forget to split the url ?

1 solution

The pathname[^] property will return everything except the host.

What you're looking for is something like this:

JavaScript
var protocol = window.location.protocol;
var host = window.location.host;
var newHost = 'About.aspx';

var url = protocol + '//' + host + '/' + newHost;
window.open(url);


Various browsers have capabilities, either built-in or by an extension, to debug JavaScript. These will allow you to debug your JavaScript, and experiment to see what certain code does and what various objects represent.

Chrome's developer tools[^]
Internet Explorer's developer tools[^]
Firebug for FireFox[^]
 
Share this answer
 
v2
Comments
miss786 17-Jan-14 11:21am    
Thank you so much for your suggestion and help. I have previously written the same code as above and I had to change it due to, making the url as window pop up. Thank you for javascript tools, I shall have a go debugging it and get back to you.
Karthik_Mahalingam 17-Jan-14 12:18pm    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900