LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2011, 02:14 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Executive a JavaScript Function along with a URL


There is this sample web page: http://website/status.aspx and it has a clickable link / button that executes a JavaScript function:

(Right-Click and Copy Shortcut would give this piece of code
Code:
javascript:__doPostBack('lbtnUpdateStatus','')
whereas the source code for the link / button is as follows:

Code:
<a id="lbtnUpdateStatus" href="javascript:__doPostBack('lbtnUpdateStatus','')">
I want to automate the above function / link along with the said URL so that I won't have to open the webpage and click the button / link.

I want a single URL hitting which we won't need to do the extra effort of "clicking the link / button" that executes the JavaScript function given above.

I can't automate this task in the source webpage itself because that has to be there as it is for the users who access the webpage.


How to achieve it?

I got some useful information here:

http://www.tizag.com/javascriptT/javascriptvoid.php

but I want to call a javascript function along with a URL such as this:

Code:
http://website/status.aspx javascript:alert("OKAY")
but the above line of code won't work.
 
Old 06-15-2011, 08:33 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You can execute javascript without a browser using several tools, for example: https://developer.mozilla.org/en/SpiderMonkey
 
Old 06-16-2011, 11:00 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Just after the <HEAD> or even <BODY>,
Quote:
<Script>
__doPostBack('lbtnUpdateStatus','')
...
...
function __doPostBack(strArg1.,strArg2)
{
// The code as it exists
}
</Script>

Last edited by AnanthaP; 06-16-2011 at 11:04 AM.
 
Old 06-21-2011, 05:04 AM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Nope, guys! That is not what I want to do. The webpage is to be used as it is. Let's say to get a report I need to open that particular webpage and then click a link / button located on it. Clicking the link / button will then fetch a report and display it on the webpage or save it to a file automatically. That functionality is already in place and I can't touch it. So, this is what I want to automate. I need to visit the webpage and click that link/button over and again and then look for a particular piece of information (status). I want to simply automate this "clicking the link/button" task so that I won't have to visit the webpage at all.

If you hit this in (on Windows XP, for example) Start -> Run:

explorer http://google.com

then it will open your default web-browser and the website/webpage will also be displayed in it. Or you can save that line in a .bat file and then have "Scheduled Tasks" run it from time to time. That is exactly what I am doing. But I need to include that "link / button", which is a JavaScrip function, with the line: explorer http://google.com so that that particular function can be executed as if the webpage had been manually opened and the button were clicked on.
 
Old 06-21-2011, 10:48 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, so you have a webpage, downloaded from a web server. The web page can be downloaded either by a conventional web browser (explorer in your example, others possible), or by a simpler tool such as wget or curl. Within that web page is some javascript, and some HTML. The HTML describes a way in which a particular fragment of the javascript is invoked.
Since the HTML causes the screen element (a link) to invoke a javascript function, and since a link is interactively activated by a user, the problem seems to become one of how to get the function invoked unconditionally.

If the page is downloaded and saved to a disk file, it can be modified by a script in a way such as AnanthaP has described. Once modified, the page can then be loaded by a conventional browser as a file:// type URL. With luck, there will be enough information in the HTML file to unambiguously perform the action described in the javascript. It may be that the URL of the server that serves the initial page request needs to be retained, and is used by the browser to complete the execution of the javascript.

If the latter is the case, then the modification of the page as a static page will fail. The solution then would be to modify the page en-route to the browser. That would require some serious system-level hacking, and if Windows is the host, LQ is probably not the ideal place to pursue that avneue. Alternatively, there seems to be a few plugins and other extensions that fall in the category of 'web browser automation'. Google will reveal a number of them. Perhaps that is a viable solution to your problem.

--- rod.
 
Old 06-21-2011, 05:40 PM   #6
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You could also look at Twill - http://twill.idyll.org/
 
Old 06-22-2011, 12:51 AM   #7
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
theNbomr: You have got it!

By the way, how do we identify if a particular website is being hosted on or served by a Linux or Windows box?
 
Old 06-22-2011, 07:27 AM   #8
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Look at the html headers to identify the server.. the Tamper data plugin for Firefox or Paros Proxy will allow you to see them.
 
Old 06-22-2011, 09:08 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by devUnix View Post
By the way, how do we identify if a particular website is being hosted on or served by a Linux or Windows box?
I think you have misinterpreted my previous reply regarding the host OS. In that, I meant the OS hosting the client (browser), since it is there that you have access to the incoming HTTP data. In most cases there is no explicit identification of the server host OS or HTPP server within the HTTP data. There may be ways to divine the nature of the server based on undocumented behaviors, but I could not describe any of those. Blackhats often make use of such characteristics in order to determine applicable exploits.
Only the browser normally reports its identity, and this is commonly used server-side for producing compatible HTTP responses.
--- rod.
 
Old 06-22-2011, 09:42 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Okay, so I may have spoken too soon and too uninformed. Having just tried running nmap against a local HTTP server, I see that it correctly identifies the distro (but not version) of the server host OS and HTTP server type and version. Not too sure where it is getting that from; perhaps using techniques I alluded to in my previous post.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript to verify correct URL szboardstretcher Programming 1 05-31-2011 08:03 AM
javascript - class / function in function jchambers Programming 3 06-15-2009 10:33 PM
embedding javascript in url mohit dhawan Programming 7 04-07-2006 10:41 AM
help with javascript function paul_mat Programming 3 02-15-2006 12:48 PM
Javascript : Importing content from another url synna Programming 0 03-02-2004 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration