AMP - how to make a link to back previous page in amp? - javascript

I am using blade template of laravel.
Do we have any way to implement back function in amp page?
I tried 3 ways but all are fail:
a on="tap:AMP.goBack" does not work
a href="javascript:history.back()" will work but it get error from validator amp.
amp-script does not support History API.

Amp dev advise me to use: AMP.goBack(navigate=true). Now it works same as javascript:history.back().
Refs:
https://github.com/ampproject/amphtml/pull/26585
https://github.com/ampproject/amphtml/issues/5225

Related

How can I build routing into a SPA jQuery app?

I am building a simple MVP of an idea in jQuery and Rails 5. I would like to avoid introducing a front end framework for the purposes of the simple project.
In order to let users navigate with the forward/back button I made different templates with "routes" such as /profile and /network as follows.
I use popstate to change which handlebars template I render (in the onPopState function):
window.addEventListener('popstate', onPopState, true);
I use pushState when I navigate to a new page (I navigate just by swapping which handlebars template and event handlers I am showing):
history.pushState({page: 'home'}, 'Page Title | Home', app.client + '/home');
I have most of the functionality working. The only problem is that if I refresh the page or type in a URL like myapp.com/profile in the address bar directly I get logged out and/or see an error, either a 404 if the app is deployed, or a Cannot GET /profile if I am running on localhost.
I think the issue is that I need to implement some kind of routing on the front end, but I am not sure how / which to use. Are there simple ways to implement this with just jQuery / JavaScript?
Thanks!

AngularJS Routing Link does not work in Chrome

I have the following HTML to route to a different view:
Contact
The route works perfectly fine on Firefox, but gives the following error on Chrome/Safari:
GET http://localhost:55951/Contacts/Create 404 (Not Found)
It looks like WebKit is trying to actually go to the address, whereas in Moz there is no navigation, and AngularJs is handling the routing.
Any ideas what would be causing this?
For any novice AngularJs developer who stubles upon this problem like I did:
After lots of head banging, I read the console log carefully, which had a reference to jQueryMobile.js. Turns out jQueryMobile does not play nice with Angular.Js.
You can do a workaround with http://jacobmumm.com/2011/08/30/angularjs-with-jquery-mobile/. I just ended up removing jQueryMobile.

How to write firefox addon to change the searchbar on right side to my own search service

Basically I have created one simple search engine in php.
I want to create a firefox addon, after installing that it will automatically add my search engine URL to the search box. And this should be default one as now "Google" is the default. So when user type anything, the suggestions should be coming from my webservice.
I'm using FF 21
Any working code or documentation will be very helpful.
Simplest method to create a search plugin is to use it as OpenSearch plugin.
https://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox
And OpenSearch plugin supports 'search suggestions' using json. But, It'll not be a default one without manually changing it.
Next method is to create a extension using XUL & JS to do whatever you want.
https://blog.mozilla.org/addons/2009/01/28/how-to-develop-a-firefox-extension
http://www.codeproject.com/Articles/31736/Introduction-to-Building-FireFox-Add-ons-Extension
https://developer.mozilla.org/en-US/docs/Firefox_addons_developer_guide/Let%27s_build_a_Firefox_extension

Angular routing without changing location

Chrome Packaged Apps have a rather strict Content Security Policy. One result of this is that manipulating the location (like clicking on a link) results in:
'Can't open same-window link to "chrome-extension://lkjasdfjklbdskjasdfjkhfdshjksad/derp.html"; try target="_blank". '
Target _blank will open the link in chrome which is not what I want. Can AngularJS' routing work in such a locked-down environment?
They docs give an example of an Angular app, but conspicuously does not use routing.
Update
Here is the link that, when clicked, gives the error: <a class='walrus-link' ng-href='paystubs/{{walrus.id}}'>Walrus {{id}}!</a>
Instead of using an href, try using ng-click and call a method to your controller the relocates to the appropriate page using $location. See the documentation on the AngularJS site. The following quote from the doc gives an indication that the $location service might be appropriate for you:
When should I use $location? Any time your application needs to react
to a change in the current URL or if you want to change the current
URL in the browser.
Your code might look something like this:
<a class='walrus-link' ng-click='getPaystub(walrus.id)'>Walrus {{id}}!</a>
and in your parent controller, you'll need a scope method called 'getPaystub' with a line similar to:
$scope.getPaystub = function(selectedWalrusId) {
$location.path('paystubs/'+$scope.walrus.id);
}
This way angular keeps control and won't cause a page refresh. This hopefully keeps you within the bounds of the CSP. Unfortunately I cannot test this in a packaged app, but I've used the exact same convention in a web app and it works just dandy.
routing works for me in my chrome app when not using $routeProvider's html5 mode (which is disabled by default), you just have to use a hash in the url.
so my links look like this:
About
$routeProvider configuration is as follows:
$routeProvider.when('/about', {templateUrl:'about.html'})

How to parse a web use javascript to load .html by Python?

I'm using Python to parse an auction site.
If I use browser to open this site, it will go to a loading page, then jump to the search result page automatically.
If I use urllib2 to open the webpage, the read() method only return the loading page.
Is there any python package could wait until all contents are loaded then read() method return all results?
Thanks.
How does the search page work? If it loads anything using Ajax, you could do some basic reverse engineering and find the URLs involved using Firebug's Net panel or Wireshark and then use urllib2 to load those.
If it's more complicated than that, you could simulate the actions JS performs manually without loading and interpreting JavaScript. It all depends on how the search page works.
Lastly, I know there are ways to run scripting on pages without a browser, since that's what some functional testing suites do, but my guess is that this could be the most complicated approach.
After tracing for the auction web source code, I found that it uses .php to create loading page and redirect to result page. Reverse engineering to find the ture URLs is not working because it's the same URL as loading page.
And #Manoj Govindan, I've tried Mechanize, but even if I add
br.set_handle_refresh(True)
br.set_handle_redirect(True)
it still read the loading page.
After hours of searching on www, I found a possible solution : using pywin32
import win32com.client
import time
url = 'http://search.ruten.com.tw/search/s000.php?searchfrom=headbar&k=halo+reach'
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 0
ie.Navigate(url)
while 1:
state = ie.ReadyState
if state == 4:
break
time.sleep(1)
print ie.Document.body.innerHTML
However this only works on win32 platform, I'm looking for a cross platform solutoin.
If anyone know how to deal this, please tell me.

Categories

Resources