Using jquery functions on an opened window

225
November 22, 2016, at 3:58 PM

I don't know if this is a simple or complex question (or if it's been asked before). I'm trying to open a webpage in my browser, say google.com, and then use jquery to grab/modify those elements. Here is my code below:

$scope.populateUrl = function () {
    var openWindow = function () {
        return $q(function (resolve, reject) {
            resolve(window.open('https://www.google.com'))
        })
    }
    openWindow().then(function (wnd) {
        console.log(wnd.document)
        var inputs = wnd.document.getElementsByTagName('input')
        console.log(inputs)
    })
}

I feel like this should be a really simple problem but when I console log wnd.document I get:

#document
  <html>
    <head></head>
    <body></body>
  </html>

And the inputs variable is empty. Shouldn't wnd.document be the html for google? If it makes a difference I'm using Node for this project.

Answer 1

As i can understand from $scope you are writing angularjs in client side.

You are trying to get google.com from your site with your user's cookies. So why not getting paypal.com after and see what your user's balance is or make some transfers? As you understand if that was possible it will cause huge security problems.

Anyway what you are trying to do is impossible.

You could try to send a get request to the site you want and if this site allows it through access controll allow origin you could get the response you want.

Although if you are just want to scrappe a site and get some data from it you should do it server side. There are several modules to do that like: https://github.com/cheeriojs/cheerio or a whole program made specific for that:http://docs.casperjs.org/en/latest/quickstart.html

READ ALSO
Identify keyboard language before keypress in Javascript

Identify keyboard language before keypress in Javascript

I was able to find code for getting current keyboard language[nnn]on-key-press, but I want to get this data on-click. [nnn]Meaning, when the user click on screen -> alert('EN/FR/SP').

330
Continue of failure of jQuery Deferred chain

Continue of failure of jQuery Deferred chain

I'm doing a series of sequential AJAX calls in jQuery, using the usual method of chaining with Deferred. The first call returns a list of values and the subsequent calls are made with those returned list entries.

242
How to output an XML node via jQuery after updating values?

How to output an XML node via jQuery after updating values?

I'm using jquery to update some node values in an xml document like this. .

232