How to find the ActionURL in a javascript __doPostBack - javascript

I'm using VBA in excel to webscrape. I'm trying to pull down the URLs of links on a website.
Do a search on this website, with any of the checkboxes near the bottom checked:(http://www.fpi.co.za/YourFinancialPlanning/FindaFinancialPlanner/tabid/3255/Default.aspx)
You'll see there's a list of names here (advisers in south africa)
If you click on the name it will bring you to a new page. That being said, the method of URL change is actually through javascript __doPostBack, which means I can't simply getelementsbyclassname().href
I know that I can simply use VBA to click the link, and then store URL, but is there any way of obtaining that URL WITHOUT navigating to it?
This is the HREF I'm dealing with:
javascript:__doPostBack('dnn$ctr4953$Clients_Custom$ctl00$rg_Members$ctl00$ctl04$lnkName','')
Is there anything around postBackOptions.ActionURL or something?

The website is an ASP.Net application. The JavaScript is auto-generated by .Net engine, and the function __doPostBack() is simply posting the arguments back to the server which is then redirecting to the other page. This means that the URL is on the server not in JavaScript, so there is no way for you to find it.

Related

Facebook API get Fanpage ID inside Page Tab

I created a Facebook App (Page Tab). This App can be added to Fanpages.
In this App, I make a call with Javascript to get the right JSON Data for my App.
The data is specific to the FB-Site where my App was been added.
I.e. when Coca-Cola adds my App to their Fan Page, I need to know that is coca cola - to get the right data.
Now, my Idea is when creating the Page Tab, save the ID from the Page. And when making a call to get the data in the page tab sending the Fanpage ID as a parameter.
I hope it is reasonably clear what I mean.
My Question is, how got access to ID of the Page?
Best with Javascript. Or is this not possible?
I would appreciate any tip!
This would be very easy with the PHP SDK. A signed_request parameter will get passed on to your iframe, and the PHP SDK offers a function called getSignedRequest() to parse it:
https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/
For example:
$sr = $fb->getSignedRequest();
echo $sr['page']['id'];
With JavaScript it would be a lot more complicated. You could try to get the signed_request parameter like this: How to retrieve GET parameters from javascript? - But you would have to deal with the parameter on your own. HereĀ“s how to parse the parameter on your own with PHP: https://developers.facebook.com/docs/facebook-login/using-login-with-games
No Facebook SDK needed in that case, btw. And it should also work with PHP <5.4.

How do I get url that is hidden by javascript on external website?

How do I get url that is hidden by javascript on external website?
ex: http://royaldesign.se/Att_Dricka.aspx
This url is constant through navigation of pages, so page content is loaded by javascript.
link location of a page:
javascript:__doPostBack('ctl00$masterContent$DataPager2$ctl00$ctl00','')
javascript:__doPostBack('ctl00$masterContent$DataPager1$ctl00$ctl01','')
javascript:__doPostBack('ctl00$masterContent$DataPager1$ctl00$ctl02','')
.....
Is there a way to analyze (manually or by PHP script) the function __doPostBack to find out about the urls?
Thx in advance
Those values are not hidden, the __doPostBack method posts back to itself. Those values passed to doPostBack represent the html ID's of the control doing the postback.
The page your looking at is written in ASP.NET also, not PHP.
You can use your browsers debug tools to see what data is being passed back to the server via javascript.
The __doPostBack javascript function is used to submit data to an asp.net page.
The first parameter to the function is the event target. This is the ClientID of the control that is being clicked.
Asp.net uses this value to raise a Click event on the server when the page gets submitted.
You can call this __doPostBack function via javascript yourself to get the same behavior as a user clicking it.
I gave some tips on "scraping" ASP.net pages on this other question: curl script just filling up the form not submitting it
The basics of simulating a POST request using CURL are discussed here: PHP + curl, HTTP POST sample code?
I would also add that if the site you are "scraping" from is owned by someone you are on friendly terms with (and not e.g. a competitor!) you may be able to save a lot of time by asking nicely for the content, or a static URL that gives you the content.

Can I change the URL string in the address bar using javascript

I've a link on my webpage, say 'about'. Clicking on it loads a particular div without refreshing the whole page using jquery .load(). This does not change the URL string in the browser address bar.
The same page can be accessed by going to www.mydomain.com/?page=about.
So what I want to do is, when the user clicks on the 'about' link, the pages will be loaded as it is (using jquery), but I want to change the URL string in the browser address bar also so that someone can actually copy or bookmark the exact page.
Is it possible to do so??
You have two possibilites to tackle this problem:
In newer browsers you can make use of the HTML5 history API, which lets change part of the URL, also the query string (and path afaik).
In browsers which don't support this, you can only change the fragment identifier # without reloading the page (via the location object). That means you have to change the URL to e.g.
www.mydomain.com/#!page=about
#! is a convention from Google to make Ajax sites crawlable. As the fragment identifier is not sent to the server, you have to detect it with JavaScript and load the corresponding data from the server.
There are jQuery plugins that help you to handler this.
I would look for a good plugin makes use of the history API if available and falls back to the hash based solution.
As written in my comment, you can also find more information here:
How to change browser address bar without reloading page, especially #ThiefMaster's answer.
Yes, I've done it by doing
location.hash = 'foo';
There's other attributes of location you can change, not sure what it's called for '?', probably query-string, get, or soemthing like that.

Javascript function execution on link click?

I have a link, that when a user clicks on it, it loads a different page as normal but also executes a JS function that autofills a specific text-box on that different page. Is it better practice to use Jquery or Javascript to do this? How can I do this using either one of them?
You can't do this from the source page.
It's a security feature. Imagine if you wrote a JS function that went to an online banking page and auto-filled a bank transfer using the user's current cookie. That's why you can't.
If you control the other page then the sequence you can use is:
Save data to the server;
Go to the new page with a JS redirect;
The new page is loaded from the server;
While loading th epage the data that was saved from the server is retrieved and used to populate the text box.
So it can be done from the server but only if you save it there. The only way of doing that is using Ajax.
An alternative approach is:
Instead of a JS redirect, submit the page back to the server;
The server saves whatever data it needs to;
The server sends back an HTTP redirect to the new page;
The new page uses the saved data to construct the new page with the populated text box.
At the end of the script add return false;. This will make the page run the script without redirecting the page.
Edit: (after saw your edition).
Is it better practice to use Jquery or Javascript to do this? How can I do this using either one of them?
jQuery is a javascript library, this it doesn't matter if you use plain javascript or use jquery as long as you happy with the result.
And about what you say that you successfully manipulated a page fro the redirecter page... I don't see how it possible.

How Do I Post and then redirect to an external URL from ASP.Net?

ASP.NET server-side controls postback to their own page. This makes cases where you want to redirect a user to an external page, but need to post to that page for some reason (for authentication, for instance) a pain.
An HttpWebRequest works great if you don't want to redirect, and JavaScript is fine in some cases, but can get tricky if you really do need the server-side code to get the data together for the post.
So how do you both post to an external URL and redirect the user to the result from your ASP.NET codebehind code?
Here's how I solved this problem today. I started from this article on C# Corner, but found the example - while technically sound - a little incomplete. Everything he said was right, but I needed to hit a few external sites to piece this together to work exactly as I wanted.
It didn't help that the user was not technically submitting a form at all; they were clicking a link to go to our support center, but to log them in an http post had to be made to the support center's site.
This solution involves using HttpContext.Current.Response.Write() to write the data for the form, then using a bit of Javascript on the <body onload=""> method to submit the form to the proper URL.
When the user clicks on the Support Center link, the following method is called to write the response and redirect the user:
public static void PassthroughAuthentication()
{
System.Web.HttpContext.Current.Response.Write("<body
onload=document.forms[0].submit();window.location=\"Home.aspx\";>");
System.Web.HttpContext.Current.Response.Write("<form name=\"Form\"
target=_blank method=post
action=\"https://external-url.com/security.asp\">");
System.Web.HttpContext.Current.Response.Write(string.Format("<input
type=hidden name=\"cFName\" value=\"{0}\">", "Username"));
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body>");
}
The key to this method is in that onload bit of Javascript, which , when the body of the page loads, submits the form and then redirects the user back to my own Home page. The reason for that bit of hoodoo is that I'm launching the external site in a new window, but don't want the user to resubmit the hidden form if they refresh the page. Plus that hidden form pushed the page down a few pixels which got on my nerves.
I'd be very interested in any cleaner ideas anyone has on this one.
Eric Sipple
I started with this example from CodeProject
Then instead of adding to the page, I borrowed from saalon (above) and did a Response.Write().
I would do the form post in your code behind using HttpWebRequest class. Here is a good helper class to get your started:
<Link>
From there, you can just do a Response.Redirect, or perhaps you need to vary your action based on the outcome of the post (if there was an error, display it to the user or whatever). I think you already had the answer in your question to be honest - sounds like you think it is a post OR redirect when in reality you can do them both from your code behind.
I have done this by rendering a form that auto-posts (using JavaScript) to the desired remote URL - gather whatever information you need for the post in the web form's postback and then build the HTML for the remote-posting form and render it back to the client.
I built a utility class for this that contains the remote URL and a collection of name/value pairs for the form.
Cross-page posting will work if you own both of the pages involved, but not if you need to post to another site (PayPal, for example).
If you're using ASP.NET 2.0, you can do this with cross-page posting.
Edit: I missed the fact that you're asking about an external page. For that I think you'd need to have your ASP.NET page gen up an HTML form whose action is set to the remote URL and method is set to POST. (Using cross-page posting, this could even be a different page with no UI, only hidden form elements.) Then add a bit of javascript to submit the form as soon as the postback result was received on the client.
I needed to open in the same window, dealing with possible frame issues from the original page, then redirecting to an external site in code behind:
Private Sub ExternalRedirector(ByVal externalUrl As String)
Dim clientRedirectName As String = "ClientExternalRedirect"
Dim externalRedirectJS As New StringBuilder()
If Not String.IsNullOrEmpty(externalUrl) Then
If Not Page.ClientScript.IsStartupScriptRegistered(clientRedirectName) Then
externalRedirectJS.Append("function CheckWindow() {")
externalRedirectJS.Append(" if (window.top != window) {")
externalRedirectJS.Append(" window.top.location = '")
externalRedirectJS.Append(externalUrl)
externalRedirectJS.Append("';")
externalRedirectJS.Append(" return false;")
externalRedirectJS.Append(" }")
externalRedirectJS.Append(" else {")
externalRedirectJS.Append(" window.location = '")
externalRedirectJS.Append(externalUrl)
externalRedirectJS.Append("';")
externalRedirectJS.Append(" }")
externalRedirectJS.Append("}")
externalRedirectJS.Append("CheckWindow();")
Page.ClientScript.RegisterStartupScript(Page.GetType(), clientRedirectName, externalRedirectJS.ToString(), True)
End If
End If
End Sub

Categories

Resources