Upload contents of current html page from a bookmarklet - javascript

What would be a good way to upload the html content of the current page viewed in the browser to another server from a bookmarklet?
Assuming this url is on a server that requires authentication, so I want to avoid fetching the page on the sever side, but rather would like to see if it's possible to get the contents and upload them directly from within the browser.
Thanks in advance for any suggestions
Elisha

Considering that you are most probably going to have a situation in which the page being viewed in the browser is on a different domain from the domain you want to send the data to, an AJAX request will definitely fail (due to Cross-Domain restrictions). So doing this server side would be your best bet.

Retrieve location.href with XHR into string
Create FORM with desired cross-site action
POST data to server
?????
PROFIT!

Related

Get Content of a page on another domain

We want to get the html content of a page on another domain. The following considerations are present:
1- The login page has a I am not a robot recaptcha.
2- The load of page in iFrame is restricted.
3- Could not use jQuery get or load methods because of cross domain restrictions.
With these limitations is it possible to develop a crawler or even use some client side codes to get data?
Thanks
Actually.. NO
But you can take the help of a backend server.
Let the server download the page and send it to the client.
This would solve problems related to CORS restrictions.
Coming to the captcha part, if the page operations are restricted by the captcha, then again there aren't much you can do. If it was that easy, the captcha wouldn't be used in the first place.

Running a client-script on loading a webpage

I want to run a script when a user tries to access a webpage.
E.g I type in google.com and as the page loads I want a client side script to
know the protocol of the page( https in this case).
I know that windows.location.protocol is one way of knowing the protocol in JS.
But how do I make this run when a user accesses a webpage in a browser.
Also can I send a request for a webpage and analyse the response using , say ajax.Suppose I send a http request to facebook. And i get a 301 redirect message.How do I analyse this response and know that this is a redirect message.
Does it require browser modifications?Can it be done without it.Thanks
Like #SachinKumar said...
1) getting and using protocol: create a browser plugin in your preferred browser. Chrome is the most obvious choice.
2) determining response: do you mean, analyze it using your own code when the user receives a 301? (Probably doable with a browser plugin.) Or, do you mean you just want to check the response of some page yourself? (Jquery's http/get functions are one clear way to do that.)

Can I request a webpage with JavaScript and then send it as is to a server to be analyzed further?

what I'm trying to achieve is to call a webpage with JavaScript get the HTML and send it to a server to be further analyzed.
Is it even possible? Where should I start looking?
I think you are looking for AJAX. It can send httpRequests on client side or please tell what do you exactly need.
You can use XMLHttpRequest to GET a page and POST it to a backend URL address.
However, you'll be limited to same-origin policy, i.e, the URL of the page you GET and the URL of the POST to receive the data must both be of same origin.
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
There are workarounds, depending on your application needs.
using Javascript to crawl the web ? bad idea : you can make it directly in your back-end

Client Side Script to Display all Images from another website

I want to have a form on my page take user input, a URL to be precise, and once that field is complete, have the script go to the destination URL that was entered (in the background), and display all images on that page in a thumbnail view for the user to select. I have been able to get it to work using php but want a client side solution. Any suggestions?
JavaScript is restricted by the same origin policy. It will not be able to read the other site unless it supports CORS. Other option is to use a local proxy [serverside langauge] on your domain to fetch the content.
Client side solution would be tricky. Most browser don't allow cross-domain AJAX calls.
Take a look at http://en.wikipedia.org/wiki/Same_origin_policy

javascript send POST request to remote server

If I have a server on xyz.com and wanted to send a POST request via javascript to abc.com how do I do this? Will I run into the Same Origin Policy? Mainly I just need to send data and not necessarily return data (although that would be nice). Any thoughts on this view? I am ideally looking for an entirely javascript method. Thanks.
If you want to post data, guessing you do not want to refresh the page. That means you need to add a hidden iframe to the page with a id/name. Set the form's target to that id/name and presto, you submit the form to that domain without refreshing the page.

Categories

Resources