Re: Open URL in Safari with Post params
Re: Open URL in Safari with Post params
- Subject: Re: Open URL in Safari with Post params
- From: Simon Forster <email@hidden>
- Date: Sat, 12 Nov 2011 17:27:22 +0000
On 12 Nov 2011, at 11:55, Axel Luttgens wrote:
> Le 11 nov. 2011 à 17:17, Simon Forster a écrit :
>
>> [...]
>>
>> At the moment I've got to download the form in Safari, fill it in (programmatically) and then submit the form. This seems somewhat inelegant and a (small) waste of my time as I've got to wait for the page with the form in to be downloaded before I can fill it in. Far better to make the call directly to the CGI with the POST data from the off - except there doesn't seem to be a method to do this.
>>
>> In pseudo-code what I'm after is:
>>
>> tell application "Safari"
>> activate
>> tell window 1 to set current tab to make new tab
>> set the URL of document 1 to "http://www.example.com/example.cgi" using post data "name=Thomas"
>> end tell
>
> Hello Simon,
>
> I now understand what you're trying to do and the constraints you're facing. :-)
> The following should do the trick:
>
> tell application "Safari"
> tell front window
> tell (make new tab)
> do JavaScript "
> var F = document.createElement(\"form\");
> F.setAttribute(\"method\", \"POST\");
> F.setAttribute(\"action\", \"https://www.somwhere.net/login.cgi");
> var I = document.createElement(\"input\");
> I.setAttribute(\"name\", \"identity\");
> I.setAttribute(\"value\", \"fred\");
> F.appendChild(I);
> var I = document.createElement(\"input\");
> I.setAttribute(\"name\", \"passwd\");
> I.setAttribute(\"value\", \"bert\");
> F.appendChild(I);
> F.submit();
> "
> end tell
> end tell
> end tell
Hmm. Doesn't work. I wonder if one's got to create a more complete page - body element and all?
Doesn't work.
I'll play a bit more to see if I can get this approach working.
Thanks for the idea.
ATB
Simon _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden