Web Analytics Made Easy -
StatCounter How can i run javascript from a URL? - CodingForum

Announcement

Collapse
No announcement yet.

How can i run javascript from a URL?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can i run javascript from a URL?

    I'm trying to test a web server from the outside and I'm not all that experienced.

    I want to enter some values in a page, and run some javascript to submit, all from within a single URL. I thought I could do this:

    https://example.rainaqa.com/LoginAct...document.forms[0]);

    However, it didn't work. Doing it in two steps will work manually, like this:

    1) https://example.rainaqa.com/LoginAct...o.com&pwd=test
    2) javascript:doSubmit(document.forms[0]);

    But this isn't good enough, because I'm trying to write a script which will loop through viewing this page (and thus logging into the server) automatically.

    Is there any way to browse to a page and run javascript all within one URL? Or a good alternative short of knowing how to code?

    Any help would be much appreciated.

    Thanks,
    Raina

  • #2
    you can use something like:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function submitViaURL(f) {
    	var a = new Array();
    	for(var i=0; i<f.elements.length; i++) {
    		if(f.elements[i].tagName.toLowerCase() == "input") {
    			switch(f.elements[i].type) {
    				case "checkbox":
    					if(f.elements[i].checked) {
    						a.push([escape(f.elements[i].name), true]); 
    					}
    				break;
    				
    				// ... radio buttons, etc here
    
    				default:
    					a.push([escape(f.elements[i].name || "noname"), escape(f.elements[i].value)]); 
    			}
    		} else if(f.elements[i].tagName.toLowerCase() == "textarea") {
    			a.push([escape(f.elements[i].name), escape(f.elements[i].value)]); 
    		} else if(f.elements[i].tagName.toLowerCase() == "select") {
    			a.push([escape(f.elements[i].name), escape(f.elements[i].value)]); 
    		} 
    	}
    	
    	var str = (f.action.charAt(f.action.length-1) == "?") ? "" : "?";
    	for(var i=0; i<a.length; i++) {
    		if(i>0) {
    			str += "&";
    		}
    		str += a[i].join("=");
    	}
    	
    	// following line for debugging
    	alert(f.action+str);
    	document.location = f.action+str;
    }
    </script>
    </head>
    
    <body>
    <form name="myForm" action="myPage.asp?" onsubmit="submitViaURL(this); return false;">
    <input type="text" name="txt" value="winkle"><br>
    <input type="checkbox" name="chk" checked><br>
    <textarea name="txtArea">sdasdsda</textarea><br>
    <input type="submit" value="submit">
    </form>
    </body>
    </html>
    Hope this gives some sort of idea

    m_n
    Last edited by martin_narg; Aug 8, 2005, 10:25 AM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

    Comment

    Working...
    X