Re: IE5 with JavaScript by AppleScript seems to be tricky
Re: IE5 with JavaScript by AppleScript seems to be tricky
- Subject: Re: IE5 with JavaScript by AppleScript seems to be tricky
- From: JJ <email@hidden>
- Date: Fri, 05 Oct 2001 19:04:40 +0200
>
To my surprise it works if Explorer is not running but is launched by the
>
script.
If you say "using terms...", you are really launching the app.
I think "using terms" is used specially to manipulate apps on remote
locations that are "running" an app that isn't "running" on your machine.
If you run the script from your machine, it launches the remote app (the
remote app, in your script, isn't remote!!!
AppleScript Guidebook says: "an app cannot be program linked unless it's
running"
>
The seconds time you run the script it does NOT WORK ANYMORE!
>
It works if placed in a HTML page and called as a function with an
>
onClick-Handler on a link (see below).
>
>
Does this mean, you cannot send an window.open-Event to Explorer the same way
>
with AS or is it a IE bug? Why does it works once, not twice?
>
>
-- ---------------------------------------------------------------------
>
>
on run
>
>
set JavaScriptCode to "
>
{
>
var mypage = 'http://www.macgix.com';
>
var myname = 'macgix';
>
var w = '800';
>
var h = '600';
>
var scroll = 'yes';
>
var winl = (screen.width - w * 1.15);
>
var wint = (screen.height - h * 1.25) / 30;
>
winprops =
>
'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+'';
>
window.open(mypage, myname, winprops);
>
if (parseInt(navigator.appVersion) >= 4)
>
{
>
win.window.focus();
"win" should be a "var". So, it's undefined. Perhaps your Explorer is
configurated to disable javascript if it encounters bad code, so, it would
explain why the script doesn't works (two, three...) times.
>
}
>
}
>
"
>
>
JavaScriptCall(JavaScriptCode)
>
>
end run
>
>
on JavaScriptCall(the_function)
>
>
set tApp to my getApp("MSIE")
>
>
using terms from application "Internet Explorer"
* Why you use "using terms..."?
>
tell application tApp
>
Activate
look at this "Activate" (different than "activate").
This is compilated from <<event WWW!ACTV>>, a IE command.
So:
<script>
using terms from application "Internet Explorer"
tell application tApp
</script>
is equal to
<script>
tell application "Internet Explorer"
</script>
>
try
>
do script the_function
>
on error errtext number errnum
>
if errnum is -108 or errnum is -50 then ,
>
error "Please open an URL in your browser before calling this function!"
>
return {errtext & " / " & errnum}
>
end try
>
>
end tell
>
end using terms from
>
>
return true
>
>
end JavaScriptCall
>
>
>
on getApp(theID)
>
tell application "Finder"
>
set theApp to (application file id theID) as text
>
set tOff to offset of ":" in (reverse of characters of theApp) as text
>
set theApp to (characters ((length of theApp) - tOff + 2) thru -1 of theApp)
>
as text
>
end tell
>
return theApp
>
end getApp
A little license:
<script>
tell app "Finder" to set theApp to name of (first process whose creator type
= "MSIE")
</script>
This example (little) works for me:
<script>
tell application "Internet Explorer"
repeat 2 times
do script "{self.resizeTo(750,600)}"
do script "{self.resizeTo(50,60)}"
end repeat
end tell
</script>
JJ