开发者

jQuery add something if PageName ==

I am working in a software that generates awful code. I need to be able to access a table cell using the PageName (URL). The pages are generated dynamically and the system adds no classes in the tables.

If the URL is /TicketingWel开发者_如何学Ccome.aspx?stuff&otherstuff

And The third TD is what I need to affect I have this which works but removes the TD on subsequent pages

                     //remove right (3rd) td
        $('table td:eq(3)').hide();

and tried to work only if PageName==

if ( $(PageName=='TicketingWelcome') {
   $('table td:eq(3)').hide();
};

But I can't get this to work and I know it's either the complete wrong way to approach this or I have the syntax wrong. The bottom line is I need help or a lobotomy.

Thanks in advance for any assistance in learning how to do this.

Kind regards


What in the name of JavaScript is a PageName? Some .net object? The best way to do JS is to forget what the server has, it doesn't matter once the browser starts rendering.

So open the browser's developer console and type in PageName, if it doesn't exist, try this location.pathname as a substitute. The window.location object holds the info of the url in the browser so you should use it instead.

For example, on this page:

alert(location.pathname);

displays

/questions/7479780/jquery-add-something-if-pagename

In the if statement you can try this:

/*
this regex will work with/without the trailing slash, but for url parameters it will take a
more elaborate test
*/
var rightPage = new RegExp('TicketingWelcome\.aspx\/?$').test(location.pathname);
if(rightPage){
    $('table td:eq(3)').hide();
}


Don't schedule the surgery. Maybe look for a new company/project though.

function onPage(name) {
  var path = window.location.pathname;
  return name == path.substring(path.lastIndexOf(‘/’) + 1);
}

if (onPage('TicketingWelcome.aspx')) {
   $('table td:eq(3)').hide();
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜