Thanks to this answer I know how to completely disable user selection on a WebView.
I would like to prevent users from selecting text/graphics in the WebView but still be able to select a text field to input text. With the above solution selecting text fields is not allowed.
It appears the changing the delegate to return [[proposedRange startContainer] isContentEditable] will allow selection on editable elements, i.e. form fields.
- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:
(DOMRange *)currentRange
toDOMRange:(DOMRange *)proposedRange
affinity:(NSSelectionAffinity)selectionAffinity
stillSelecting:(BOOL)flag
{
return [[proposedRange startContainer] isContentEditable];
}
On my site I have a DataList full of image thumbnails. The thumbnails are HyperLink controls that, when clicked, offer an enlarged view of the source image (stored in my database).
My client wants a facebook Like button on each image and I was hoping to put that in the lightbox window that appears when you click on a thumbnail.
My challenge here is that to generate the info for the Like, I need to create meta tags and each image should, preferably, create it's own meta tags on the fly.
What I can't figure out is how to make the HyperLink click open the lightbox AND create the meta tags at the same time.
Any help will be greatly appreciated.
For a live view of the site, go to http://www.dossier.co.za
The way that we approach similar problems is to hook the onclick event of the href in javascript.
Depending on exactly what you need to do, you can even prevent the standard browser behavior for the hyperlink from executing by returning false from the javascript method.
And in some cases, we just use the hyperlink for "show" by setting the href to "#".
Here is an example that combines all of these concepts:
File Name
In this case, the specified javascript is executed, there is no real hyperlink, and the browser doesn't try to navigate to the specified URL because we return false in the javascript.
Add a Classname to the opening table tag like class="tbl_images" so we can use JQuery to access it. Capture the click on the td and pickup the id of the item. Pass that id to your code as required to generate your meta tags. In the following when the user clicks on an anchor in a td, a function will run.
I use this all the time to access attributes in the td so i can run a function. You could use something like this to pickup values from your image/anchor and create something...
$("#tbl_images > tbody > tr ").each(function () {
//get the id of the tr (if required)
var id = $(this).attr("id");
var ImageTitle = $(this).find("img.Image_Class_Name").attr("title");
//on click of anchor with classname of lighthouse run function,
//passing in our id or other data in the row to our function
$(this).find("td: > a.lighthouse").click(function () {
//update script for this record
MyFunction(id,ImageTitle);
});
});
I already used document.getElementById, but it does not work any more. I want to get the value of 0,01€ but I can not. I want to save it in my NSString *price but how.
The HTML code is
<tr class="price">
<td>0,01</td>
<td>EUR</td>
My idea was
NSString *price = [webView stringByEvaluatingJavaScriptFromString:#"document.getElementsByTagName('price.td').innerText;"];
The tagName in this case is 'td' not 'price.td', but if you run document.getElementsByTagName('id') you will get all the table cells in the page which is probably not what you want.
If the page has jQuery loaded in it you can use jQuery('.price td:first').text() to get the price.
If it doesn't have jQuery but you have control of the page you can add a class to it (<td class="my-price">12.44</td>) and get it with document.getElementsByClassName('my-price')[0].innerHTML.
If you don't have control of the page and it doesn't have jQuery you will have to find the 'price' row and then get its 1-st cell by using document.getElementsByClassName('my-price')[0].childNodes[0].innerHTML.
Also, a cleaner and more flexible approach is to use the Selectors API:
http://www.w3.org/TR/selectors-api/
document.querySelector('.price td:first').innerText
I have a label on top of the image view.
Every time some one pushes the button the label is filled with a string that comes from a server.
I have a button that calls the picker to select a photo from the picker but the label obviously keeps empty..
How can i make sure the string will be saved with the photo and when i call it back with the picker it fills the label again...
I need some tips/help...
i am using ASIHTTPREQUEST asynchronical call to fill the label...so it does not hang up...thats best practice right ? or should i use nsurl and nsstring with format ?
you may use imageview's tag and store each string with tag of image view.
Somethings are not clear here :-
1>from the client sid eyou can send a request to server with the image that has been changed and get the corresponding string(in a table probably you have have to store string for each image).
2>You might use a dictionary to store key(string) for every corresponding imageName and store it in a dictionary and if you want persistent storage you may use coredata or sqlite.
To ensure that both the image and string are shown at same time you can show an activityIndicator.
I'm developing a mobile app (iOS 5.0 and above compatible) for a website where users can view certain data directly from their landing page. The user can refine the results by selecting specific options (i.e. location and/or date). They don't offer any web service calls, and won't allow us to access their database. So my only resort of collecting the data is from 'scraping' the site directly.
My issue is that I don't know how make the changes that the users can make on the site from a http request from the phone. For example the site below:
can be pulled from the site and saved as a string with the following command
NSString *html = [NSString stringWithContentsOfURL:urlrequest encoding:NSUTF8StringEncoding error:&err];
I'm able to separate the relevant data:
// I decided to add the script function name in case anyone wanted to look for themselves
<script type="text/javascript" language="Javascript">
//<![CDATA[
function loadData(){
var winMsgTitle = "Date: 04/11/2012";
// this is the actual data I'm concerned with:
gLatLong = new GLatLng(31.59019444444444, -110.50655555555555);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", ".84", "5711", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
gLatLong = new GLatLng(32.2938260182, -110.7896411419);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", "1.00", "1254", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
gLatLong = new GLatLng(33.5966853633, -112.1744066477);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", ".70", "256", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
Note: There are obviously more points, this is just snip it
In order to get another location, or date, I have to manually select via the site and select the options on the right hand pane. My question is, how do I make those changes programmatically via objective-c?
I suppose you use UIWebView to load that page.
One possible solution is to write JavaScript functions to simulate normal user operations on the right hand pane (for example, use jQuery's trigger function to select the drop down list, select 'Date Range', etc.).
These javascript functions could be coded as strings in your app code.
Then, call stringByEvaluatingJavaScriptFromString: on the webview to run these javascript functions:
[webView stringByEvaluatingJavaScriptFromString:javascript]
Here the javascript parameter is a string you construct that calls your javascript functions. For example:
NSString *javascript = [NSString stringWithFormat:#"selectRegion(%#)", targetRegion];
When doing this, I'd suggest you write these javascripts and test them using a browser's debug tool(Safari's Web Inspector, Firefox's FireBug plugin...) to make sure they work as expect first.
If i understand you correctly, you want to pull the data without displaying the website to your user?
If yes, the only solution i can currently think of would be an off-screen UIWebView, in wich you do some JavaScript-magic to simulate user-input, and then get the data out.
This is however a very hackish approach and i would not suggest you use this in a shipping application.
In fact, i would suggest not doing any webscraping at all, because if they change their sites structure, your app fails to work.
If you are really developing an app "for them" then go tell them that you need a webservice in order to write a good application.
If you are not working "for them" but are just trying to write an app that uses their service to get data, then what you are doing is not only complicated, but does most probably also violate their EULA and you should therefore not be doing that at all. Consider contacting them and see if you can get them to work with you in that case.