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: Axel Luttgens <email@hidden>
- Date: Fri, 11 Nov 2011 15:00:12 +0100
Le 10 nov. 2011 à 18:21, Simon Forster a écrit :
>
> Hi
>
> Hoping someone can help me. I'd like to open a URL in Safari and submit some post params at the same time. I can achieve the end result quite easily using Safari's `do JavaScript` functionality:
>
> tell application "Safari"
> activate
> tell window 1 to set current tab to make new tab
> do JavaScript "location = 'https://www.somwhere.net/';
> onload = function() {
> document.forms[0].item1.value = 'fred';
> document.forms[0].item2.value = 'bert';
> document.forms[0].submit();
> }" in document 1
> end tell
>
> But being an impatient blighter I find that waiting for the the first page to load is a waste of time. Why not go straight to the page I want, submitting the post parameters as I go - but I can't find the syntax.
Hello Simon,
Emmanuel's suggestion could well be worth at try, after all: often, in such simple cases, servers do not really care about the method (GET vs POST), provided they get the expected parameters.
So, let's say above form on your hypothetical 'https://www.somwhere.net/' page has those items of interest:
method "login.php"
input field "identity"
input field "passwd"
You could then try:
https://www.somwhere.net/login.php?identity=fred&passwd=bert
If successful, you should immediately be on the page you're interested in, and you could even proceed without any javascript code at all.
But there's a price: the url with its confidential info would be stored in the browser's history.
Otherwise, you could have a look at the XMLHttpRequest object:
http://developer.apple.com/library/safari/#documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/XHR.html#//apple_ref/doc/uid/TP40006227-SW1
But I'm not sure you could avoid an intermediate page, because of javascript's security model (cross-site scripting concerns).
HTH,
Axel
_______________________________________________
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