0

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

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

4

2 回答 2

0

改变这个:

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

对此:

<script src="MyConfig.js" type="text/javascript"/>
于 2013-10-10T09:07:35.160 回答
0

The path of script path should be relative not absolute.
It should be like

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

Also you are using anchor tag and onclick so you should be returning false form your function.

于 2013-10-10T09:12:47.257 回答