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 7639485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:25:47+00:00 2026-05-31T08:25:47+00:00

I am trying to load a page and then run a javascript code on

  • 0

I am trying to load a page and then run a javascript code on it, I found a Greasemonkey script that does the same, but I am having problems implementing the same thing in android, probably because I don’t know anything about javascript.

This is the Greasemonkey script; it’s supposed to a give a new link:

window.addEventListener("load", function ()
{   
    var link = document.evaluate("//div[@class='dl_startlink']/div/a[contains(@href,'"+window.location.href.match(/\?(.*)$/)[1]+"')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    if( !link.snapshotLength )
        return;     
    location.href = link.snapshotItem(0).href;      

}, false);

and this is how I want to run it:

public void onPageFinished (WebView view, String url) {
                System.out.println("webview loaded");
                webView.loadUrl("javascript:/*...........Javascript code here........*/");

           }

Any ideas on how I get that link and load that page in the webview?
EDIT: Another version does the same thing.

var candidates = document.evaluate("//*[@class = 'dl_startlink']/div", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
 if( !candidates.snapshotLength ) 
return;
//The DIV with the highest zIndex has the *real* link; the rest are useless.
- var maxDiv = candidates.snapshotItem(0);
- for( var i = 1; i < candidates.snapshotLength; i++ )
- if( maxDiv.style.zIndex < candidates.snapshotItem(i).style.zIndex )
- maxDiv = candidates.snapshotItem(i);
- location.href = maxDiv.children[0].href; 
  • 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-31T08:25:49+00:00Added an answer on May 31, 2026 at 8:25 am

    Ok, here’s only simple Xpath query, which may be rewritten as CSS selector.

    Also I decided to replace window.location.href.match(/\?(.*)$/)[1]. If my version will not work, replace first 2 lines with var query = window.location.href.match(/\?(.*)$/)[1];.

    Actually, maybe even var query = window.location.search.replace(/^\?/,'') is enough.

    window.addEventListener("load", function ()
    {   
        var l = window.location;
        var query = l.search ? (l.search.replace(/^\?/,'') + l.hash) : ""
    
        var link = document.querySelector("div.dl_startlink > div > a[href='" + query + "']");
        if (!link) return;
        l.href = link.href;
    }, false);
    

    New code for Android:

    var candidates = document.querySelector("div.dl_startlink > div");
    if( !candidates.length) 
        return;
    //The DIV with the highest zIndex has the *real* link; the rest are useless.
    var maxDiv = candidates[0];
    for( var i = 1; i < candidates.length; i++ )
        if( maxDiv.style.zIndex < candidates[i].style.zIndex )
            maxDiv = candidates[i];
    location.href = maxDiv.children[0].href; 
    

    Compacted version:

    webView.loadUrl("javascript:window.addEventListener('load',function(){var%20candidates=document.querySelector('div.dl_startlink>div');if(!candidates.length)return;var maxDiv=candidates[0];for(var%20i=1;i<candidates.length;i++)if(maxDiv.style.zIndex<candidates[i].style.zIndex)maxDiv=candidates[i];location.href=maxDiv.children[0].href;},false)");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load page and then remove some elements in it. While doing
I'm trying to load a page that is basically an edit form inside a
I'm trying to load a page using the load() function, the problem is that
I am trying to load generics within the aspx page. Here is my code
So I'm trying to load some returned html from an .aspx page but a
I found a JavaScript error in a script that I'm developing. I whittled it
I'm trying to load one page into another using the .load() method. This loaded
I am trying to load mschart in my aspx page(SalesOverview.aspx) using jQuery.load() method, I
I am trying to load a flash player onto an html page. The page
I'm trying to load a DIV element from an external page into my current

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.