Listen for url changes on opened windows?

14 views
Skip to first unread message

scottg...@gmail.com

unread,
Oct 23, 2012, 7:10:52 PM10/23/12
to node-...@googlegroups.com
Hey all,

Forgive me if I've missed something obvious here (I'm coming from the front end dev world, so am a little out of my element), but I'm wondering if there's a way I can listen for url changes on an opened window? I've tried:

openedWindow.addEventListener("load",function() {
  alert(openedWindow.location.href);
});

But it fails to report the location beyond the initial page load. Have also tried polling openedWindow (not elegant I know), but it reports 'swappedout://' as the href as soon as I change the url in the nw address bar and fails thereafter.

I suppose I'm looking for an extension to the window api - something like the tabs.onUpdated api for Chrome Extensions

Thoughts? 


Cheers,
-Scott


Zhao Cheng

unread,
Oct 25, 2012, 2:10:24 AM10/25/12
to node-...@googlegroups.com
After the window has changed its URL, its javascript context will be
completely lost. Event you can listen to the url change event, you
will not be able to get new window's `window` object, which means you
can do nothing with the new window. This limitation is determined by
browser nature.

So you should never refresh the whole page, you need to use ajax to
refresh only part of your page.
--
Cheng
Intel Open Source Technology Center

Roger

unread,
Oct 25, 2012, 2:12:21 AM10/25/12
to node-...@googlegroups.com
On Thu, Oct 25, 2012 at 2:10 PM, Zhao Cheng <zcb...@gmail.com> wrote:
After the window has changed its URL, its javascript context will be
completely lost.

Right. But the Node's context would not? So the code in Node context can do this job.

Roger

Roger

unread,
Oct 25, 2012, 4:56:57 AM10/25/12
to Zhao Cheng, node-...@googlegroups.com

And that's why we need to fix #36 [1], which should be the only way to define functions in Node context.

[1] https://github.com/rogerwang/node-webkit/issues/36

Roger

scottg...@gmail.com

unread,
Oct 29, 2012, 5:51:10 AM10/29/12
to node-...@googlegroups.com, Zhao Cheng
Now that the #36 fix is in, I'm curious about how I would do this properly.

Have tried the following code window api code in app.js which is defined as node-main in the manifest.

<code>
var gui = require('nw.gui');
var newWindow = gui.Window.get(
window.open('http://google.ca');
)
</code>

This seems to throw an error (the nw ui just goes grey). Is this a bug or am I doing something wrong?

Roger WANG

unread,
Oct 29, 2012, 10:17:58 AM10/29/12
to node-...@googlegroups.com, Zhao Cheng
<scottg...@gmail.com> writes:

> Now that the #36 fix is in, I'm curious about how I would do this
> properly.

At least in my testing the fix didn't work. Will re-open the issue and
follow up on this.

> Have tried the following code window api code in app.js which is defined as
> node-main in the manifest.
>
> <code>
> var gui = require('nw.gui');
> var newWindow = gui.Window.get(
>
> window.open('http://google.ca');
>
> )
> </code>
>
> This seems to throw an error (the nw ui just goes grey). Is this a bug or
> am I doing something wrong?

Even after #36 works, 'nw.gui' and windows objects cannot be opened
here (which should be another item on our TODO).

A callback function should be defined here and then referred from
WebKit context (e.g. from your index.html)

--
Roger WANG Intel Open Source Technology Center

scottg...@gmail.com

unread,
Oct 29, 2012, 8:02:58 PM10/29/12
to node-...@googlegroups.com, Zhao Cheng
Opened issue #128.

Roger, thanks for the quick reply and your continued hard work on node-webkit.

Let me give some context to my question here... I'm working on an application that will use node-webkit as a browser for the web at large with some added node functionality in the background, so access to index.html is a bit tricky to say the least.

Is this kind of project 'in scope' for nw?


Cheers!
-Scott

Roger

unread,
Oct 29, 2012, 8:08:07 PM10/29/12
to node-...@googlegroups.com
Sure it is in our scope.

Roger


From: scottg...@gmail.com
Sent: Tue Oct 30 08:02:58 格林尼治标准时间+0800 2012
To: node-...@googlegroups.com
Cc: Zhao Cheng <zcb...@gmail.com>
Subject: Re: [node-webkit] Listen for url changes on opened windows?

Roger WANG

unread,
Jan 14, 2013, 10:38:10 AM1/14/13
to node-...@googlegroups.com, scottg...@gmail.com
Roger WANG <roger...@intel.com> writes:

> <scottg...@gmail.com> writes:
>
>> Now that the #36 fix is in, I'm curious about how I would do this
>> properly.
>
> At least in my testing the fix didn't work. Will re-open the issue and
> follow up on this.

Just had a try and it's working with 'loaded' event on the Window
object:

https://github.com/rogerwang/node-webkit/wiki/Window

You can use it from Node context:

var gui = window.require('nw.gui');
gui.Window.get(win).on('loaded', function() {
window.console.log(window.location.href); });
Reply all
Reply to author
Forward
0 new messages