Reputation: 263
Is it possible to extract the value of a variable used in java script in a web page. I need to get the url stored in javascript function in a web page. In web page the function is called using <a href
,
when we click on that hyperlink , java script function is called and the url is returned.
Below is the code,
<a class="dld" OnClick="download_file();" href="javascript:"> </a>
The script function is
function download_file() {
var summaryFlag = 0;
if(document.getElementById("frmincludefile").checked){
summaryFlag=1; }
url = '/filedatabase/file_process_request.html?mru=53616c7465645f5f3f24b8f4a86301eb202e67fbb679df4356e24fee9d7a17a099010eb5acf5985c&type=doc';
url += '&sum='+summaryFlag+'&logo=0&xcode=xtritiuminx&serve_txt=0&folderid=';
document.location = url;
}
How can i get value of url variable.
Upvotes: 0
Views: 1042
Reputation: 263
I was not able to the result of java script function but now i'm invoking the javascript using
webBrowser1.Document.InvokeScript("download_file");
By invoking the java script i'm able to download the file.
Upvotes: 1
Reputation: 25682
You can do this using variable in the upper scope. In the example bellow I'm using global variable (bad practice) to save the localUrl
value from the redirect function:
var url = '';
function redirect() {
var googleRadio = document.getElementById('google');
if (googleRadio.checked) {
localUrl = 'http://google.com';
url = localUrl;
}
}
Upvotes: 0
Reputation: 658
Set the URL
var value in any hidden field
for e.g.
document.getElementById("hidden_field_name").value = url;
Upvotes: 0