从另一个调用1个外部javascript函数

时间:2013-10-10 09:03:56

标签: javascript jquery html asp.net html5

我在下面的代码中遇到问题,

MyConfig.js(这是一个外部的js文件)

function myFunction()
{
    var tfile = "file://";
    // Server Location(should be changed at the time of deployment)
    var location = "inhyds149";
    // Document folder location. The user documents will be pulled from here.
    var staticpath = "/Documents/pdfs/";
    var n=tfile.concat(location,staticpath);
    return n;
}

我的HTML内容::

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="generator" content="Adobe RoboHelp 10" />
        <title>Third</title>
        <link rel="StyleSheet" href="default.css" type="text/css" />
        <script src="D:\Test\MyConfig.js" type="text/javascript"/>
    </head>
<body>
    <script>
       function myFinal()
       {
           var tfile1 = myFunction();
           var location1 = "Holidays 2013.pdf";
           // Document folder location. The user documents will be pulled from here.
           var n1=tfile1.concat(location);
           return n1;
        }
    </script>
    <h1>Third</h1>
    <p>Dynamically hyperlink pdf to <span style="font-weight: bold;">'welcome'</span> 
       keyword</p>
    <p>&#160;</p>
    <p><a id="Link" onclick="myFinal()" target="_blank">Welcome</a></p>
</body>
</html>

我的要求是将我从外部js文件获取的结果与我的js文件中的location1中的值相连,并将其输入到click。请帮忙。

实际上我需要动态生成一个位置。因此外部JS函数将包含路径的一部分,而内部JS函数将包含剩余的部分。我只想连接它们并打开PDF。所以这将是myFunction将返回说:// abc / xyz我将在我的html中有一个字符串,我必须合并它们说://abc/xyz/l.pdf我只想打开这个pdf

2 个答案:

答案 0 :(得分:0)

改变这个:

<script src="D:\Test\MyConfig.js" type="text/javascript"/>

到此:

<script src="MyConfig.js" type="text/javascript"/>

答案 1 :(得分:0)

脚本路径的路径应该是相对的而不是绝对的 它应该像

 <script src="foldername/MyConfig.js" type="text/javascript"/>

此外,您正在使用锚标记和onclick,因此您应该返回false函数。

相关问题