Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSObject.call(method, ARGS) with Safari

Reply
Thread Tools

JSObject.call(method, ARGS) with Safari

 
 
Arved Sandstrom
Guest
Posts: n/a
 
      04-23-2012
On 12-04-22 04:07 AM, Richard Maher wrote:
> "Richard Maher" <(E-Mail Removed)> wrote in message
> news:jn02en$5gp$(E-Mail Removed)...
>>
>> "Daniel Pitts" <(E-Mail Removed)> wrote in message
>> news:YOGkr.11325$(E-Mail Removed)...

>
>>> Not sure if this helps, but in the past I've had to do some hacky
>>> work-arounds to work with JSObject.
>>>
>>> Check out:
>>> <http://virtualinfinity.net/wordpress/tools/2008/10/11/javascript-and-java-applets/>
>>>

>>
>> Anyway, I'll give your code/solution a go shortly but I'm not hopeful
>> given that I can't even get a simple appletWindow.call("topLevelFunction",
>> args) to do other than return "null". Without arguments is not a problem.
>>
>> So in the meantime if anyone knows of an example JSObject.call("sayHello",
>> WITHargs) that works in Safari can they please provide a pointer?
>>
>>> Daniel.

>
> As expected, still no joy and a nullpointer. (And now IE complains that you
> can't cast a String to JSObject)
>
> Thanks anyway.
>
> Anyone else done this on Safari?
>>

> Cheers Richard Maher
>>
>> PS. NO *NOT bloody EVAL* - call, Call, CALL()!
>>


I don't usually deal with Java applets of any kind, but this was
interesting. I worked up a Swing JApplet and have a JavaScript function
an a JSP page.

Since you mentioned Safari I did Safari 5.1.2 on Mac OS X 10.6.8 with
Java Plug-in 1.6.0_31.

The applet has text fields to take 2 numbers, a result text field, and a
"submit" button. The JavaScript function is

function addNums(one,two) {
return one+two;
}

and the important 2 lines of code in the applet are

JSObject win = JSObject.getWindow(this);
Object sum = win.call("addNums", new Object[] {num1, num2});

where 'num1' and 'num2' are java.lang.Doubles. So is 'sum'.

There is not anything more to it. It worked just fine.

AHS

--
A fly was very close to being called a "land," cause that's what they do
half the time.
-- Mitch Hedberg
 
Reply With Quote
 
 
 
 
Richard Maher
Guest
Posts: n/a
 
      04-23-2012
Hi Arved,

On Apr 23, 8:17*am, Arved Sandstrom <(E-Mail Removed)>
wrote:
> On 12-04-22 04:07 AM, Richard Maher wrote:
>


> Since you mentioned Safari I did Safari 5.1.2 on


>>> Mac OS X 10.6.8 with <<<<


Well there goes 3 days of my life I'll never get back I guess some
would say I deserve it for not being a OS/X user. I should have
pointed out that I was running Safari of Windows XP but on 2nd
thoughts, who cares? I can't see many users choosing to browse with
Safari on Windows so, in the grand scheme of things it can stay broke.
(Shame to not be able to test there though).

.. A couple of other observations on Safari Liveconnect support for
those following at home
1) removeMember is not support on WIN or OS/X (Either does Chrome for
that matter)
2) WIN Safari supports get/set Member but OS/X does not

> Java Plug-in 1.6.0_31.
>
> The applet has text fields to take 2 numbers, a result text field, and a
> "submit" button. The JavaScript function is
>
> function addNums(one,two) {
> * return one+two;
>
> }
>
> and the important 2 lines of code in the applet are
>
> JSObject win = JSObject.getWindow(this);
> Object sum = win.call("addNums", new Object[] {num1, num2});
>
> where 'num1' and 'num2' are java.lang.Doubles. So is 'sum'.
>
> There is not anything more to it. It worked just fine.


Yep, pretty wonderful and useful stuff eh?

Thanks for testing it for me.

>
> AHS
>


Cheers Richard Maher
 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      04-23-2012
On 12-04-23 03:40 AM, Richard Maher wrote:
> Hi Arved,
>
> On Apr 23, 8:17 am, Arved Sandstrom <(E-Mail Removed)>
> wrote:
>> On 12-04-22 04:07 AM, Richard Maher wrote:
>>

>
>> Since you mentioned Safari I did Safari 5.1.2 on

>
>>>> Mac OS X 10.6.8 with <<<<

>
> Well there goes 3 days of my life I'll never get back I guess some
> would say I deserve it for not being a OS/X user. I should have
> pointed out that I was running Safari of Windows XP but on 2nd
> thoughts, who cares? I can't see many users choosing to browse with
> Safari on Windows so, in the grand scheme of things it can stay broke.
> (Shame to not be able to test there though).

[ SNIP ]
>
> Thanks for testing it for me.
>>
>> AHS

>
> Cheers Richard Maher


I'm not one to resist a challenge, I tested the applet against Safari on
my Windows XP, and it worked also.

Safari 5.0.3, Windows XP, JDK 1.6.0_31 (and corresponding plugin).

FWIW my test environment is very spare. The JApplet itself is
uncomplicated, and the 2 lines I showed you are the only ones that talk
to JavaScript. The JavaScript is the function I showed, and it's the
only JavaScript in the page that contains the applet. And my applet tag
*is* an <applet> tag, not an <object> tag, with only the 'code' and
'archive' attributes. I'm not saying you want to, or can, simplify that
much (considering you want to support many browsers) but it's what
worked for me in Safari on both Mac OS X and Win XP for this scenario.

AHS
--
A fly was very close to being called a "land," cause that's what they do
half the time.
-- Mitch Hedberg
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Safari and Firefox on MAC OS X gabe garza ASP .Net 2 03-29-2005 12:12 AM
Safari Postback Problems WizyDig ASP .Net 2 12-02-2004 06:03 PM
PostBack doesn't fire the first time with Safari 1.2.1 Ian Cox ASP .Net 2 06-23-2004 09:52 AM
Safari Browser compatible with dotnet Hemlata Shah ASP .Net 2 03-04-2004 04:39 AM
Safari Display Problem Jane Hawkins ASP .Net 1 12-23-2003 03:09 PM



Advertisments