Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an 4 asp file with common javascript function.

Now i want to keep all the common function in other file and call that function from asp files.

sample code:

XML
<%--
     Generated by ASP2ASPX 4.5.
     ASP2ASPX home page: http://www.netcoole.com
     Original File Name: C:\wwwroot\VWOnline\Sign.asp
--%>

<%@ Page language="c#" Debug="true"%>

<%
    string home = "";
    string flavour = "";
%>
<%
    Response.Buffer = true;
%>



<%
    home = Request.QueryString["Home"];
    flavour = Request.QueryString["VWOFlavor"];
%>


<%
    if (Request.Form["JreDloadHome"] != "")
    {
        Session.Add("VWOViewer", 0);
        Session.Add("strHome", Request.Form["Home"]);
        Session.Add("JreDloadHome", Request.Form["JreDloadHome"]);
        Session.Add("VWOPDloadHome", Request.Form["VWOPDloadHome"]);
        Session.Add("VWOFDloadHome", Request.Form["VWOFDloadHome"]);
        if (Request.Form["VWOFlavor"] == "Lite")
        {
            Session.Add("VWOViewer", 1);
            Response.Redirect("VWOnLite.aspx");
        }
        if (Request.Form["VWOFlavor"] == "Plus")
        {
            Response.Redirect("VWPlus.aspx");
        }
        if (Request.Form["VWOFlavor"] == "Full")
        {
            Response.Redirect("VWApp.aspx");
        }
    }
%>


<HTML>
<HEAD>
<TITLE>Local Check</TITLE>
</HEAD>
<BODY>

<SCRIPT  LANGUAGE="JavaScript1.3">
var ViewWiseOnlineScriptVersion = 300;
var Netscape6 = false;
var IE5 = false;
var ViewWiseOnlineHome="";
var ViewWiseOnlineObjVersion=0;
var jreDownloadLink="";
var vwoFDownloadLink="";
var vwoPDownloadLink="";
var vwoFlavor="Lite";
var browserType="";

window.onload = initViewWiseOnline;

function initViewWiseOnline()
{
    prepareDownloadLink();
    WhoIsBrowsing();
    if (!(Netscape6 | IE5))
    {
        alert("Browser not supported");
        return;
    }
    isInstalledVwo();
    DisplayOptions();
}
function prepareDownloadLink()
{
    VWOurl= window.document.URL;
    index = VWOurl.lastIndexOf("/")
    VWOurl = VWOurl.substr(0,index);
    jreDownloadLink  = VWOurl+"/dload/jre-6u45-windows-i586.exe";
    vwoFDownloadLink = VWOurl+"/dload/ViewWiseOnline.exe";
    vwoPDownloadLink = VWOurl+"/dload/ViewWiseOnlinePlus.exe";
}

function WhoIsBrowsing()
{
    var BrowserInfo = navigator.userAgent;
    var MozillaIndex = BrowserInfo.indexOf("Mozilla/");
    var MSIEIndex = BrowserInfo.indexOf("MSIE ");
    if (MSIEIndex != -1)
    {
        browserType = "IE";
        var IEVersion = BrowserInfo.substr(MSIEIndex+5,2);
        if(IEVersion.indexOf(".") != -1){
            IEVersion = IEVersion.substr(0,1);
        }
        if (IEVersion >= 5) IE5 = true;

    } else if (MozillaIndex != -1)
    {
        browserType = "Mozilla";
        var NSVersion = BrowserInfo.substr(MozillaIndex+8,1);
        if (NSVersion >= 5) Netscape6 = true; //Mozilla Brow. will work!
    }
}
function isInstalledVwo()
{
    try
    {
        if (IE5)
        {
            //alert("Calling Activex");
            var obj = new ActiveXObject("CVOOCX");
            ViewWiseOnlineObjVersion = obj.Version;
            if (ViewWiseOnlineScriptVersion > ViewWiseOnlineObjVersion )
            return(false);
            ViewWiseOnlineHome = obj.Home;
            //alert(ViewWiseOnlineHome);
            if(ViewWiseOnlineHome == ""){
                ViewWiseOnlineHome = "<%= home %>";
            }
            //alert(vwoFlavor);
            vwoFlavor = obj.Flavor;
            if(vwoFlavor == ""){
                vwoFlavor = "<%= flavour %>";
            }
            return(true);
        }
        if (Netscape6)
        {
        //  ViewWiseOnlineHome = "C:\Program Files\ViewWise Online"; and vwoFlavour = full
            ViewWiseOnlineHome = "<%= home %>";
            vwoFlavor = "<%= flavour %>";
            return(true);


            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            var obj = Components.classes["@computhink.org/VWO;1"].createInstance();
            obj = obj.QueryInterface(Components.interfaces.coIVWO);
            ViewWiseOnlineObjVersion = obj.vwoVersion;
            if (ViewWiseOnlineScriptVersion > ViewWiseOnlineObjVersion)
            return(false);
            ViewWiseOnlineHome = obj.vwoHome;
            vwoFlavor = obj.vwoFlavor;
            return(true);
        }
    }

    catch (e)
    {
        if (e == "enablePrivilege not granted")
        {
            document.writeln('<P> This site requires extended privileges. </P>');
            document.writeln('<P> You need to add the following line:</P> ');
            document.writeln('<P> <STRONG> user_pref("signed.applets.codebase_principal_support", true); </STRONG>');
            document.writeln('<P> to the prefs.js file in Mozilla user profile directory or to the  </P>');
            document.writeln('<P> all.js file in the <STRONG>pref</STRONG> directory then restart Netscape. </P>');
        }

        return(false);
    }
}
function DisplayOptions()
{
    var tmpViewWiseOnlineHome = ViewWiseOnlineHome;
    var tmpjreDownloadLink = jreDownloadLink;
    var tmpvwoPDownloadLink = vwoPDownloadLink;
    var tmpvwoFDownloadLink = vwoFDownloadLink;
    var tmpvwoFlavor = vwoFlavor;
    //document.write('<FORM name="frmlogin" action="Sign.aspx" method=post>');
    //document.write('<input NAME=Home type= hidden />');
    //document.write('<input NAME=JreDloadHome  type= hidden />');
    //document.write('<input NAME=VWOPDloadHome  type= hidden />');
    //document.write('<input NAME=VWOFDloadHome  type= hidden />');
    //document.write('<input NAME=VWOFlavor  type= hidden />');
    //document.write('</FORM>');
    document.frmlogin.VWOPDloadHome.value = tmpvwoPDownloadLink;
    document.frmlogin.VWOFDloadHome.value = tmpvwoFDownloadLink;
    document.frmlogin.JreDloadHome.value = tmpjreDownloadLink;
    document.frmlogin.Home.value = tmpViewWiseOnlineHome;
    document.frmlogin.VWOFlavor.value = tmpvwoFlavor;
    document.frmlogin.BrowserType.value = browserType;
    document.frmlogin.submit();
}
</SCRIPT>
<FORM name="frmlogin" action="Sign.aspx" method=post>
    <input NAME=Home type= hidden />
    <input NAME=JreDloadHome  type= hidden />
    <input NAME=VWOPDloadHome  type= hidden />
    <input NAME=VWOFDloadHome  type= hidden />
    <input NAME=VWOFlavor  type= hidden />
    <input NAME=BrowserType  type= hidden />
</FORM>
</BODY>
</HTML>
Posted
Updated 24-Oct-13 2:21am
v2
Comments
Ashwani Gusain 24-Oct-13 8:31am    
Nawab sahab kya chahtay hai aap?

create a .js file in your project and add reference to it in the page header where you want to use any of the function from this file.


like this.

XML
<head>

<script src="../../Project/javascripts/Common.js" type="text/javascript"></script>

</head>



Further to create a .js file , go to Add new Item option from project hierarchy(Right Click on Project Name in solution Explorer) and select JScript File option.


Hope it will help. :)
 
Share this answer
 
v2
SQL
create a javascript file outside and call it in site.master page as shown below

<%: Scripts.Render("~/Scripts/yourscript.js")%>

which you can call in any page that is you can call any function from that page in any page
 
Share this answer
 
v2
Add all function in single JS file. add this file into head section of page after that you can use the function available in that JS file.
 
Share this answer
 

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