2013-10-10 20 views
0

我有在下面的代码问题,调用1个外部JavaScript函数从另一个

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中的值连接起来,并在点击时提供给它。请帮忙 。

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

+0

你想用你的函数'myFinal()返回的值做什么?' –

+0

其实myFinal应该返回字符串值,它将是pdf的位置,我只想打开PDF – user2866242

+0

并点击你想要的打开pdf的权利? –

回答

0

更改此:

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

这样:

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

对不起,这没有帮助。 – user2866242

0

脚本路径的路径应该是相对的不是绝对的。
应该是这样

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

而且你正在使用锚标记和onclick,所以你应该返回假表的功能。

+0

您可以请发布代码。我是HTML开发新手。谢谢 – user2866242

+0

你想从你的功能想要什么不清楚? –

+0

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

相关问题