0

I am making simple bot which will take values from script then it will put them into the textboxes of another website and then perform click on button so the bot can log in another website I have written the code, but I want to call it when page is fully loaded. I tried <body onload> but it doesn't work.

Is this possible that we could call our javascript function from our c# code file under the documentcompleted event or any other way?

<script type="text/javascript">
    function myf() {
        document.getElementsByTagName("INPUT")[1].setAttribute("value", "userabc");
        document.getElementsByTagName("INPUT")[2].setAttribute("value", "passwordabc");
        document.getElementsByTagName("INPUT")[3].click();
    }
</script>

//C# Code file
protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect("https://www.iauc.co.jp/auction/prelogin01_en.jsp?timestamp=1360652615774");
}

protected void Page_LoadComplete(object sender, EventArgs e)
{
    //Can we call javascript function here    
}    
1
  • You should also probably be using a framework like jQuery in your myf function. It will improve cross-browser behaviour. Commented Jan 23, 2014 at 12:59

3 Answers 3

1

I did not fully understand you but if you want to run a script when the document has been fully downloaded on the client web browser, then you can user jQuery's document ready event.

Add jQuery to your web page and then add the following script block to the page after the jQuery reference.

<script type="text/javascript">
    $(function () {
        // write your JavaScript code here
        myf();
    });
</script>

This script block will get triggered when the DOM for the page has been fully loaded.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to write the complete java script including script tag in a string variable. Then you can Response.Write() the string variable.

string script = "<script type="" language=""> YOUR JAVASCRIPT </script>";
Response.Redirect(script);

Comments

0

Try this

// here's will be your script
string script = "";
ClientScriptManager clientScript = Page.ClientScript;
clientScript.RegisterStartupScript(typeof(Page), "a key", script);

UPDATE :

this will check it if its fully loaded and then do what you want


$(document).ready(function() 
 {
   //page is fully loaded and ready, do what you want
 }

1 Comment

This means, that the script will be executed at the loading of the page, or rather, as soon as the script is hit. This might not be fully desired.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.