Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Object [object global] has no method 'attachEvent' #5

Open
hems opened this issue Oct 14, 2015 · 9 comments
Open

Comments

@hems
Copy link

hems commented Oct 14, 2015

By forcing the HASH api on ways-addressbar like this:

screen shot 2015-10-14 at 18 49 45

i'm getting an error: Uncaught TypeError: Object [object global] has no method 'attachEvent' on chrome.

@arboleya
Copy link
Owner

Seems like the window object is not available (source code).

@hems
Copy link
Author

hems commented Oct 14, 2015

How is that even possible, Mr. Holmes?

@arboleya
Copy link
Owner

For instance, if you call this method on a server instance (nodejs, iojs, nw, electron) which doesn't have a window object - or it's not available yet by the time you initialize ways.

You didn't provide more details about your context, so I'm assuming some possibilities here. :)

Makes sense?

@hems
Copy link
Author

hems commented Oct 14, 2015

totally, was more of a joke. i'm investiganting

@arboleya
Copy link
Owner

Oh wait, the problem is the method attachEvent which apparently only exists on IE? Hash support was built for IE only, I guess.

So for using hash in a forced way, there must to be added some cross-browser capabilities to it, among tests of course.

@hems
Copy link
Author

hems commented Oct 14, 2015

okie dokie. i went into this route because i'm having the classic "base_path" issue when using it inside of node-webkit.

it does work allright when testing on OSX but on my virtual machine with a "mounted folder" it's getting confused. i'll have a better look soon.

i tried using page.js from TJ which did not have this issue, but in the other hand for some reason doesn't trigger the routes when the pushState changes ( using node-webkit 0.8.6 ).

i thought this was supposed to be easy :P

@arboleya
Copy link
Owner

In this case here, it seems simple. :)

Basically one have to demystify a cross-browser way to do attachEvent, addEventListener etc, so every browser gets happy.

Cross-porting this code block should be enough:

window.attachEvent('onhashchange', function(){
  self.emit('url:change', self.pathname())
}, false);

However, you've mentioned the base_path thing, if it can potentially move your forward, it's another option to fix instead, much like what we started talking here a while ago.

@hems
Copy link
Author

hems commented Oct 15, 2015

yeah, will probably use a base_path hack

@hems
Copy link
Author

hems commented Oct 15, 2015

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants