I've put UIWebView in my app which loads login page, after user logs in, can I write some function that will copy specific link from that UIWebView that is specific for every user?
The best way to do this would probably be to include a JavaScript function in the page that returns the link or data you need. See [UIWebView stringByEvaluatingJavaScriptFromString:]
Another way could be to retrieve the HTML in your iOS code, get the data you need, and then set that content in the UIWebView using the loadHTMLString:baseURL: method.
Related
I am making an app in which I get text from my server and display it in UIWebview. After some time more text is added and client(iphone) is notified about the additional-text. Now I want to inject this text into my UIWebview.
One method is to update some text file and reload the content. But I dont want to reload the page.
Another way can be to use javascript to check updates in a local file (which seems better).
Is there any known better solution?
If you are getting the data from the server, why not just use JavaScript and preform an AJAX request to update the page?
This allows you to skip the middle man of updating the 'template' file. Just load all of your data with AJAX in order to always have the most 'up-to date' data on the page.
$.ajax({
url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
}
});
I believe javascript is better if you want to keep all user edited data (if there is some).
And also should be faster than reloading all page.
With the iPhone UiWebView is it possible to prefill an html form with username and other
account details that are stored in the app's data folder. Using iOS 5.1 sdk
So I would need to read the file with the customers's information stored and then prefill the web form from the UIWebView. I need to know if this can be done and if so any tutorials how to do it would be useful.
Thanks
You could read the data from your app's bundle then run a JavaScript function that takes the data as parameters and uses it to pre-populate the form.
You can execute the Javascript in your UIWebView by using the method
stringByEvaluatingJavaScriptFromString:
I'm not a JavaScript expert so I don't want to comment on the best way to write the JavaScript function to pre-populate the form but I know its possible.
I have a UIWebView in my view controller. This UIWebView shows a PDF file. I have created a button. When the user clicks on this button, I want to send the content of the UIWebView via email. As a template I use the MailComposer from Apple. In this template Apple isn't using a UIWebView. Apple uses local stored data which works fine. So I am looking to send the content of the UIWebView, my displayed PDF, but I don't know how to do this.
Thanks.
You could try using -stringByEvaluatingJavaScriptFromString: to get the HTML content of the page and using -setMessageBody:isHTML: to set the message body. You may want use a <base /> tag, though, to set the page's base URL so relative URLs function.
Edit
You could download the PDF and use addAttachmentData:mimeType:fileName: to attach the PDF to an email.
What you will need to do is download the pdf and save it on the device and then attach it as per Apple' example.
see one approach to downloading here
Let's say that I have a link to a webpage that contains some text. What's the easiest way to grab this text to process?
Thanks.
Long story short, I don't think it's possible to make a request from the client js to grab the text from a url with a different domain.
It is possible to make requests to load json. This link describes how.
Basically, the steps are:
Embed a tag in the GWT page
after GWT page is initialized, update
the script tag's src to load remote
url
remote url returns some json data
padded inside a callback javascript
function such as:
callback({blah:foo})
So, you're only option may be writing a method on the server side that loads the url, gets the text. You could then call this method from gwt client using normal rpc technique.
Assuming same origin: use the "RequestBuilder" class.
If you are trying to grab a webpage from a different origin, then it obviously won't work.
Using an iFrame, someone on my website can access their Facebook account, display a list of their photo albums, and then display photos from selected albums.
At the moment, when the user clicks a photo, I display a dialog box that shows the photo's path.
All of the above works perfectly.
My next step is to pass the photo's path info back to my web page, but I'm not sure how to do that because the object, to which I want to pass the data, is outside of the iFrame and therefore unknown to Facebook. I tried going top-down by referencing it through the DOM that contains the iFrame on my website...
parent.client.document.getElementById("FBPhoto").setValue(photoReference);
...but that didn't work.
Passing the argument to a PHP script, on my site, won't work because I don't want to fresh the page on my site (since that would cause the user to lose data).
From what you've provided it looks like your JS might be wrong.
Doing something like this might get you the value you need:
var photoReference = window.frames["iframe-name"].document.getElementById("FBPhoto");
Then you need to assign it to something:
MyObject.setValue(photoReference);
Note: window.frames["iframe-name"].document.getElementById("FBPhoto") will return the DOM element called #FBPhoto and will therefore be a big chunk of HTML. Your setValue() method might not be expecting that.
I suggest you try running your script in Firefox with Firebug installed, which will allow you to dump the value of photoReference to the console to see what you're getting back.
Doy... I realized that since the Facebook connection was running in a dedicated iFrame, it wouldn't be a problem to re-direct that frame because there was no reason to leave it open anyhow.
For anyone interested, here's what I did...
The PHP (inside of index.php) displays the album photos.
The PHP also surrounds each img frame with href tags.
The link points to a PHP file (on my website) and includes an argument with the location of the large version of the photo (since my app is displaying thumbnails). Something like: "< a href="pathToMySite/get-photo.php?photopath=facebook's path ">
When the user clicks on the desired photo, its respective link calls get-photo.php (on my site) and passes the path for the photo.
get-photo.php then inserts a reference to my website's main JS file into the document head, and inserts a script into the body of the HTML document.
The script calls a JS fetch-photo function, and passes the path argument that it received from the embedded iFrame that was running the Facebook app.
The JS function closes the iFrame (since I'm done with Facebook at that point) and grabs the photo from Facebook.