I have a Javascript function on my webpage that I’m displaying in a UIWebView:
$(document).ready(function() {
// index to reference the next/prev display
var i = 0;
// get the total number of display sections
// where the ID starts with "display_"
var len = $('div[id^="hl"]').length;
// for next, increment the index, or reset to 0, and concatenate
// it to "display_" and set it as the hash
$('#next').click(function() {
++i;
window.location.hash = "hl" + i;
return false;
});
// for prev, if the index is 0, set it to the total length, then decrement
// it, concatenate it to "display_" and set it as the hash
$('#prev').click(function() {
if (i > 1)
--i;
window.location.hash = "hl" + i;
return false;
});
});
So what I need to do is simulate an anchor click when my UIButton is clicked:
- (IBAction)next:(id)sender {
[animalDesciption stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"next\").click();"];
}
But this doesn’t work!
It works great on an HTML page, just by clicking the anchor that has an id of “next”.
Any ideas why this won’t work when clicking the button?
BTW I am able to call a standard javascript function like myFunc() with my current setup, but it won’t do anything like this!
Any thoughts would be very appreciated!
You could implement javascript functions for next and previous and call that directly from your UIButton.
The call from your UIButton would be:
By the way: I think you forgot to use
lenin thenext()function to avoid stepping over the last display section.