0

I have li something like this.This code is from some website and I don't have permission to modify that code.

<li class="History_lisitem_logout ui-last-child" data-icon="power">
                        <a id="History_lisitem_logout" name="lisitem_logout" dsid="lisitem_logout" tabindex="2" class="History_lisitem_logout ui-btn ui-btn-icon-right ui-icon-power">
                        <h3>Sign Out</h3>
                        </a>
                    </li>

I need to call that website from my ios or android app and if user click on that li, i need to trigger my own native code.

If it is normal button, I can easily do like this to call my native code.

        webView.stringByEvaluatingJavaScript(from: "$(document).on('touchstart', '#History_lisitem_logout', function() {window.location = 'ios:logoutGleer';});")

However, the issue is that I don't have 'id' in 'li' and I cannot inject my javascript code to detect event for clicking 'li'. How shall I do?

1 Answer 1

1

Anchor tag has id; make use of it.

let listEl = document.getElementById("History_lisitem_logout").parentElement
Sign up to request clarification or add additional context in comments.

8 Comments

thanks. after I get listEl, how can I call window.location ? Sorry i am not very good at this.
window.location is usually used to navigate to a particular website; For ex if you open your browser console and type this, window.location = "google.co.in" ; end hit enter your browser will take you to google
yes. i need to trigger onclick for listEl. When it is clicked, I need to call window.location.
window.location to where?
To something like this. window.location = 'ios:logoutGleer' . It will help me to call my native ios code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.