0

I am having problem in the below code,

MyConfig.js (this is an external js file)

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;
}

My HTML content ::

<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>

My requirement is to concat the result which I am getting from the external js file with the value in location1 in my js file and feed it to on click . Please help .

Actually requirement is I need to generate a location dynamically . SO the external JS function will contain a part of the path and the internal JS function will contain the remaining . I just want to concat both of them and open that PDF. So it will be myFunction will return say : //abc/xyz And I will have a string in my html and I have to merge them say : //abc/xyz/l.pdf I just want to open this pdf

  • what do you want to do with the returned value form your function `myFinal()` – शेखर Oct 10 '13 at 09:16
  • Actually myFinal should return string value and it will be a location of pdf , I just want to open the PDF – user2866242 Oct 10 '13 at 09:17
  • and on click you want to open pdf right? – शेखर Oct 10 '13 at 09:19
  • Not very sure if this is the problem but i see a silly mistake here. This line "var n1=tfile1.concat(location);" should be "var n1=tfile1.concat(location1);" – samar Oct 10 '13 at 09:20
  • Yes I want to open PDF And Samar corrected that issue :) But still not working . I feel the concatenation aint happening. – user2866242 Oct 10 '13 at 09:23
  • This seems to be a silly query but is this location "\\inhyds149\Documents\pdfs\..." accessible from your local machine? Assuming you are still under development and you are testing this code from your local machine. – samar Oct 10 '13 at 09:41
  • Yes it is accessible Samar . I think I am doing something wrong while returning the string value from MyConfig.js function – user2866242 Oct 10 '13 at 09:42
  • Have a look at this link. Maybe it will help you. http://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript – samar Oct 10 '13 at 09:55

2 Answers2

0

Change this:

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

to this:

<script src="MyConfig.js" type="text/javascript"/>
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.

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • Can you please post the code . I am new to HTML development . Thanks – user2866242 Oct 10 '13 at 09:16
  • Actually requirement is I need to generate a location dynamically . SO the external JS function will contact a part of the path and the internal JS function will contain the remaining . I just want to concat both of them and open that PDF. So it will be myFunction will return say : //abc/xyz And I will have a string in my html and I have to merge them say : //abc/xyz/l.pdf I just want to open this pdf – user2866242 Oct 10 '13 at 09:21
  • Error I am getting is :: The value of property MyFinal is null or undefined, not a function object. – user2866242 Oct 10 '13 at 09:30
  • put that file inside your application and set the relative path. – शेखर Oct 10 '13 at 09:36