PDA

View Full Version : running javascript in lzx


wlam
12-18-2003, 10:39 AM
Hi,

I'm trying to run a javascript in lazslo. The javascript I'm trying to run looks something like "window.external.blahobject.blah()".

At first I tried to put this in a script tag, but it didn't work. I later on read that browser related functionality is not supported by laszlo.

The next thing I tried was creating a dataset that makes a request to a jsp file that has the above function. e.g.

jsp file:
<html>
<body onload="window.external.blahobject.blah()"/>
</html>

lzx file:
<method>
something.setUrl(SPECIAL_URL);
something.doRequest();
</method>

I can see that the url is being requested, but the function is still not called.

Is there any ways that you would recommend so that I can run this javascript within lazslo?

antun
12-18-2003, 10:46 AM
You could try:


LzBrowser.loadURL("javascript:myJavaScriptCode()");


If you want the myJavaScriptCode function to be one that you define, then you should declare it in the HTML wrapper page. See here on how to do that:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=25

Alternatively myJavaScriptCode() could be a function call on the default browser DOM. The only thing I should warn you about here is that it is the browser that controls what JavaScript calls are allowed using the javascript: syntax. For example, you can't submit a form this way, although you can open a new browser window.


The next thing I tried was creating a dataset that makes a request to a jsp file that has the above function. e.g.


That will never work. For a start the idea of a server-side request being able to call random browser JavaScript is a huge security concern. That's why no browser supports this as far as I know. You can only run browser JavaScript that's on the HTML page you have.

Furthermore, when you make a data request from a Laszlo application, you're not requesting an HTML page. You probably noticed that the page didn't refresh at all - the request goes out from and returns to the Flash client in the browser, which does not understand or use HTML.

Hope this helps!

-Antun

wlam
12-18-2003, 11:00 AM
That is working perfectly. Thanks!!

- Wendy