...

View Full Version : Is it possible to use client side .js file to load a local .html file?



peterbi
05-18-2009, 09:05 PM
Hi,

I have a .js file, we want to make it to load a html file right next
to it, both files are on client system. I couldn't find any such
examples and some posts talked about JavaScript security issues, I
wonder if it is related to what I want.


Please suggest, and even better, provide sample or pseudo code.


Someone said .js file is not really JaveScript file, though Microsoft
named it 'JavaScript'.

Please also note that I am trying to "call" .html file from the .js file, not embed html code in .js.


Thanks,
Peter

Old Pedant
05-18-2009, 09:51 PM
I have a .js file, we want to make it to load a html file right next
to it, both files are on client system.

Ummm...

(a) What does "right next to it" mean??

(b) Do you want to do this IN A BROWSER? Or do you really mean you want to execute the ".js" file's code via the Windows Script Host?

(c) In any case, if both files are on the client, then you could have a security issue, if you want to do this with a browser.

Maybe you could show us some of the code in that file??

rnd me
05-18-2009, 11:27 PM
the .js file wont run on it's own, it needs an HTML shell.
if the files are in the same folder, you can simply ask for them by file name.

peterbi
05-19-2009, 12:07 AM
Thanks for your reply.

a) 'right next' means both file are in the same folder or under the same parent folder (haven't decided yet).

b) Well, I think I meant to execute the '.js' file with WSH. I am not 100% sure because the '.js' file will be called by a 'widget' file (.kon, which is an xml file), Yahoo!Widget engine has a function "include()" so you can 'include' a .js file instead to embed js code inside the xml file. So I don't think .kon call the .js file via BROWSER.

c) That's right (they both are on client) and that's what I have problem with. Is there any way to avoid this? Such as using different script (vbs) or other ways to launch .html files?


Thanks,
Peter

peterbi
05-19-2009, 12:13 AM
I forgot to post the sample code - it's simple though.

Here is the widget code (.kon file):


<?xml version="1.0" encoding="UTF-8"?>
<widget debug="on">


<window>
<image name="skin">
<src>Resources/dividerart.jpg</src>
</image>
<image>
<src>Resources/button.png</src>
<hOffset>150</hOffset>
<vOffset>80</vOffset>
<onMouseUp>
openURL("www.msn.com"); //as example
</onMouseUp>
</image>
</window>

<action trigger="onMouseUp">
include("main.js");
</action>

</widget>

And simply a separate "main.js" file that try to launch an html file (in the same directory, or parent/sub directories).

Please note that I have tried to find a way to directly launch .html file from the .kon file, but no luck yet.


Thanks,
Peter

Old Pedant
05-19-2009, 01:52 AM
rnd_me: No, if you are running on Windows, then you *can* use JScript (almost the same as JavaScript...MS dialect thereof) in "standalone" mode thanks to the MS's inclusion of the Windows Script Host. Essentially, this is one way that MS makes up for the lack of a decent command language, a replacement of sorts for the various Linux "shell" languages.

Old Pedant
05-19-2009, 02:00 AM
Peter: I think you need to ask your question in a Yahoo Widgets forum. My *guess* would be that the Widgets engine does *not* allow you to run local scripts, because that would be a HUGE security hole. Note that browsers don't allow local scripts, by default, for the same reason. Only if a user gives explicit permission does MSIE, for example, permit a local script to run in the browser.

http://www2.konfabulator.com/forums/

KevinJohnson
05-19-2009, 07:59 AM
Hi,

I have a .js file, we want to make it to load a html file right next
to it, both files are on client system. I couldn't find any such
examples and some posts talked about JavaScript security issues, I
wonder if it is related to what I want.


Please suggest, and even better, provide sample or pseudo code.


Someone said .js file is not really JaveScript file, though Microsoft
named it 'JavaScript'.

Please also note that I am trying to "call" .html file from the .js file, not embed html code in .js.


Thanks,
Peter

There is a way to do this, however i only know how to do it in FireFox/Mozilla. There is one constraint though. You can only do this in an offline webpage (run from the local filesystem).
The other option is to write an XPI file (firefox extention that uses XUL language...which is really just XML+HTML+JS)

In the javascript code snippets section i made a post about loading and saving data directly from the local file system.

http://www.codingforums.com/showthread.php?t=166585

Old Pedant
05-20-2009, 02:54 AM
This code will *NOT* run in a browser. At least the ".js" file won't.

It will run in a Yahoo WIDGET. That's a special *DESKTOP* application (you know, a ".exe" in windows) that allows some limited (not sure HOW limited) usage of standard JavaScript.

And apparently Yahoo WIDGETs have some special permissions/abilities with the local filesystem. Nothing to do with browser usage thereof.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum