In an Ember app I'm building, I have a hash-only link like so: Foo, on a page that isn't the root (i.e. localhost/bar). If I inspect the element in the console, the href property is localhost#foo, instead of localhost/bar#foo like it is on other sites. window.location.href return localhost/bar, so the browser definitely knows where it is.
What could be causing this discrepancy?
I'm not sure if hash links can work with client side routing right outside the box.
I think you could check out ember-href-to which should always generate correct url for you.
Something like
<a href={{concat (href-to "some-route") "#myhash"}}>
(concat helper is not a default Ember helper)
That should provide correct url, but making the anchor actually work, that's another problem. Switching to query-params would be much easier.
EDIT:
Apparently there's this addon as well: https://github.com/mike-north/ember-anchor
Related
I know the title might make you confuse.
I have a ParentComponent called ChildComponent.
ChildComponent using eval to do some stuff. And the worst thing is, the eval's value can pass by users.
Maybe users will input some bad thing for the whole application, so I'm trying to prevent it.
The first solution that comes to my head is loading ChildComponent into an iframe (like a code-sandbox), so it can protect my Application (anything eval just affect the iframe).
But it has some problems: styles couldn't load correctly.
I asked about that problem but got no answer How to load completely an Angular component into an iframe?
I'm stuck, any idea for my problem is really appreciate
First, an iframe doesn't prevent anything.
You can just call window.parent to get a reference to the parent window.
Second, this looks like an XY problem : do not ask for help on what YOU think is the best solution, but rather explain the goal you are trying to achieve.
Finally, know that eval will NEVER be safe, so you should use it at your own risk.
But then again, JS as a whole is not safe, you can just open the dev tools and hack into any website.
I'm doing web scraping with Python. I need to get links for all the search result pages. However, I found the href value is not a regular html link but something as below. How could I get the right page link? Thanks!
2
3
You need to find the showDocumentSearchResult function in the JS code (it might be in a separate file though). Then knowing what that function does, you might simulate such an action by Python if it's ever possible.
See a following example: https://webscraping.pro/download-a-file-from-a-link-in-python/
I have a promo block, that contains several images and links. Some of them are leading to my site, some to external resources. Currently, i use this piece of code for this links.
<a {{ bindAttr href="link" }}><img {{ bindAttr src="image" }} /></a>
However, this actually reloads a page, and i don't want that in case i'm navigating inside my site. Also, it could mean breaking my app if we encounter some non-existent routes, in case of typos or whatever.
So, what i'm trying to do is to add an action, that checks if the route exists and then do a proper transitionTo, and if the route doesn't exist do some sort of default fallback, but i don't know how to make this check. Have anyone did something similar already?
P.S. I know that transitionTo could accept urls as a parameter, but Ember docs say
It is also possible to pass a URL (a string that starts with a /).
This is intended for testing and debugging purposes
and should rarely be used in production code.
And doesn't help with preventing transition if the route doesn't exist.
You could have a default route that would be a 'catch-all' which you would specify in your router as something like:
this.route('badRoute', {path: '/*pathname' });
at the bottom after you have declared all your routes. When none of your routes match, this will be matched and you can redirect or whatever when it transitions to that route.
For dynamic page changes without having to reload the whole content, I have found this very simple working solution:
Tutorial: http://css-tricks.com/rethinking-dynamic-page-replacing-content/
Demo: sudojesse.github.io/dynamic-page/
However, this solution only works if you're linking to something like "sitename.html". Is it possible to do the same with folder paths?
Example:
Like it is above:
[sudojesse.github.io/dynamic-page/about.html][1]
Like I want it:
[sudojesse.github.io/dynamic-page/more/about/][2]
I have tried it but it doesn't really work!
http://sudojesse.github.io/dynamic-page/about.html
http://sudojesse.github.io/dynamic-page/more/about/
If you want it to work, you would have to rename the file to "index".
The reason for this is because the Web server looks after a specific resource when the client requests a directory. This resource is often by default set to "index"(dot)"something".
I am using hash-based navigation in my AngularJS app rooted at /.
If a user navigates to my app like this:
http://example.com/?foo
A moment after the page loads, something (possibly Angular) is causing the address bar to look different than I expected.
What I saw:
http://example.com/?foo#/?foo
What I expected to see:
http://example.com/?foo#/
Why is this happening, and can I turn it off?
I'd wager you need to be in 'html5 mode' to not have the hash fragment... though I'm uncertain.
http://docs.angularjs.org/guide/dev_guide.services.$location
$locationProvider.html5Mode(true).hashPrefix('!');
In your app configuration, you can mess with that config param and it'd probably get rid of it.
This appears to be duplicating the hash with the path.
Check out the $location service. It has both path() and hash() methods. The second, duplicated part is the hash, the first part is the path.
Unless you are using html5 mode, all of Angular's part of the URL appears in the fragment. The problem is that Angular doesn't know about the base part of the URL (perhaps the ?foo was needed just to get Angular to load) so it won't attempt to manipulate it, it just puts its own stuff on as a fragment.
I suggest the best thing would be to check $window.location.search for a query string, and if you find one do the redirect to the URL you actually want yourself. You'll still need to do that redirect by assigning to $window.location rather than $location and it will force your angular app to reload but at least you'll end up where you want to get to.
Alternatively you could reconfigure your web server to make the appropriate rewrite, but you may not want to or be able to do that.
Or you tell your users to only use URLs they got from the app, not to try to make them up for themselves.