开发者

Javascript code in asp.net master page dependent on currenty open page

开发者 https://www.devze.com 2023-01-11 05:21 出处:网络
I have a problem with my JS script. I have written a function in my Site.Master because I use it in every page of my website. Right now I need to add a new line to that function (execute another funct

I have a problem with my JS script. I have written a function in my Site.Master because I use it in every page of my website. Right now I need to add a new line to that function (execute another function) but, and this is the whole problem, the function to be executed is only defined in one of my content pages.

To be honest it doesn't even cause any problems for me, everything works correctly, but I don't want to leave a call to the non-existing function in the rest of my content pages. So what I need is to define somehow that the last line of my master page function well be only executed 开发者_如何学Cif the page I am on is the one with the definition of that function.

Any ideas how to do that?

I am sorry for so confusing explanation of the problem...


You could try the following:

if (typeof MyFunction == 'function')
{
    MyFunction();
}

This will only call MyFunction if it exists on the current page.


Just check to see if the function is there before you call it. if (typeof foo != 'undefined') foo()

0

精彩评论

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