Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:19:17+00:00 2026-05-27T10:19:17+00:00

How can I click on a link by using the stringByEvaluatingJavaScriptFromString method in a

  • 0

How can I click on a link by using the stringByEvaluatingJavaScriptFromString method in a UIWebView? The actual hyperlink itself is different every time but the wording (“Test”) inside the Test code is always the same.

How would I go about doing this? I have had a suggestion to do the following (which doesn’t work and doesn’t do anything):

var fonts = document.getElementsByTagName('font');
for(i=0;i<fonts.length;i++) {
  if (fonts[i].innerHTML == 'Test') {
  fonts[i].parentNode.childNodes[0].click();
  break;
 }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:19:18+00:00Added an answer on May 27, 2026 at 10:19 am

    Looks like you have an answer including the Objective-C code you need, but I would imagine that for the javascript you can simply fire the contents of the link’s onclick or navigate to the appropriate url instead of going through the trouble of simulating a mouse click. Granted, I have not tested this in an iOS app but feel free to give it a shot:

    var links = document.getElementsByTagName('a');
    for(i=0;i<links.length;i++) {
      if (links[i].innerHTML.indexOf('Test') != -1) {
      clickLink(links[i]);
      break;
     }
    } 
    
    function clickLink(linkobj) {
     var onclickHandler = linkobj.getAttribute('onclick');
     if (onclickHandler == null) window.location = linkobj.getAttribute('href').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
     else eval(onclickHandler(linkobj));
    }
    

    By the way, there is an eval in this code that will run the contents of the onclick handler. This can be unsafe. If you only need to navigate to a location specified by the link then you may want to remove the portion dealing with onclick.

    A much simpler version of this is printed below (since your sample code does not appear to need to deal with onclick) which may be easier to use. In this case I am calling it after a 1-second delay, but in reality, since it seems that this code runs in response to a trigger on the iOS side (button click?), you should not use a delay and instead simply wait enable the trigger until loading is complete – webViewDidFinishLoad.

    function clickLink() {
        var links = document.getElementsByTagName('a');
        for (i = 0; i < links.length; i++) {
            if (links[i].innerHTML.indexOf('Prev') != -1) {
                window.location = links[i].getAttribute('href').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
                break;
            }
        }
    }
    
    setTimeout(clickLink, 1000);
    

    jsFiddle which demonstrates this using your sample code: http://jsfiddle.net/fzKL7/5/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this flash application where you can click a link while watching a
i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
Is there a link format that a user can click that can open the
I'm using win32com.client to control an IE instance in Python. How can I click
I am using jQuery idTabs plugin. I want to give click link (href) feature
I have a small scraper where I need to click an anchor link using
I have a link_to_remote and I want to make sure people can only click
I have noticed in phpMyAdmin you can click 'optimise' on tables, and it runs:
In many browsers today you can click and drag images. Can I leverage this
I want my website to have a checkbox that users can click so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.