Using Javascript function on other page
I have a javascript function in the default.aspx page of my asp.net website project. I need to use that page in my myfolder/test1.aspx page. How can i refer to other page? without having to cre开发者_如何学Cate a js file of my javascript page on default.aspx page...
The Javascript has to be loaded for each page. So unless you put it in a separate .js file which you reference from each page you'll have to repeat the code - which is a very bad idea.
Just go with the separate .js file. You probably already have .css files you reference - it's no different to that.
It is not possible to do so without having a common js file containing the functions.
You can't refer to embedded JS files in other pages. You should create a separate .js file and include it in the pages where you want to use it.
A separate .js file is probably the best way to do it. If there are dynamic values being generated by the default.aspx page, you could make your .js file something like CommonJS.aspx, and have that return JavaScript instead of markup. Also, you could create a user control that contains the JS code, and include the user control on multiple pages.
精彩评论