简体   繁体   中英

How to open a webpage and run your JavaScript on it?

I am trying to load a webpage then insert my own Javascript into it.

I have the current code here:

window.location.assign('http://http://79.170.44.75/hostdoctordemo.co.uk/downloads/vpn/index.php');

document.getElementById('address_box').value = prompt("Site Address: ");

document.getElementById('go').click();

and what I am trying to do is:

  1. Load the webpage
  2. Set the address box to a value
  3. Simulate a mouse click on the search button

So it loads the webpage, then searches a value it sets itself.

The problem with my current JavaScript is that as soon as the webpage has loaded the JavaScript stops working (as I expected). I have tried using the iframe tag to load the webpage 'within the webpage' but that did not work when obtaining the id and people said iframe would also not work because of the resolution difference.

**The Question: ** How do I load a webpage and run my own JavaScript code on it? Thank you!

  • Matthew

I really can't see an easy way to do what you want. When the browser receives a web page from a server the javascript is interpreted, and only after that, the page is presented on the screen.

So you would have to have a web page with a button or other mechanism to make a request to a web server, receive the request, save its contents locally, add your javascript code and only then "give it to the browser".

您可能正在寻找类似Greasemonkey的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM