Google AMP - Save current page URL to local storage - javascript

Can anyone point me in the right direction? I'm building a landing page that is supposed to store the current page URL with query strings to local storage. I've looked all over, but can't find a solution that will keep my AMP page valid.

I know this is a 3 year old question, but what you're trying to accomplish is doable through the use of the amp-script component.
You can read up here:
https://amp.dev/documentation/components/amp-script/
Hope this helps somebody in the future.

Nowadays you can use for custom JS and access the localStorage, but as far as I know, you can't access the page URL directly.
Look at this compatibility table: https://github.com/ampproject/worker-dom/blob/main/web_compat_table.md
Document.location is marked as false.
I'm working in an AMP project that needed the current page URL. What I did was to save the URL as an attribute and use a custom JS to read from this attribute (my pages are rendered in the server, so I can add this info there).

This is not possible with AMP as you can't run custom Javascript. This means you won't be able to read from local storage either.

Related

Does Facebook crawler currently interpret javascript before parsing the DOM?

Following link seems to tell that it can't: How does Facebook Sharer select Images and other metadata when sharing my URL?
But I wanted to know if it is still the case at current date...
(The documentation on facebook dev site doesn't give any precision about this point)
In the tests I've run I've never seen it interpret the JS, but that might be contextual / domain-specific (who knows).
To test your specific case, use the Facebook linter: https://developers.facebook.com/tools/debug
(log into FB first)
That's the only way to be sure 100% sure how FB will parse your page (what properties it will infer)
Yes, that is still the case (and I wouldn’t expect it to change anytime soon).
The Open Graph meta information must be provided by the server, so that it can be read from the HTML code when the URL is fetched.

localstorage or sessionstorage can't persist data on cross browser

I am working on a small application but I am stuck on a problem. I want stored form element values on a HTML page when filled in on one browser(Ex. Firefox) and auto fill data when same page is loaded in another browser(Ex. Chrome). If anybody has any ideas please help me.
Unless clients can login and you're willing to share this data via your server, you can not change behavior of a different browser from your current, so in your example Firefox can not change a cookie, localstorage or whatever of Chrome. Browsers tend to only share information like cookies when they are first ran; such as with you the import wizard from Firefox.
I can think of two alternatives to achieve this:
An authentication system where the data is stored server-side.
Through custom browser extensions. You could create a custom browser extension that directly writes the data of the other browsers. This does require the user to install that extension though.
This link explain how to achieve that http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/
It's not simple, but it's the way that I know it can be done at the moment without the use of cookies.

How can I get the next/forward url with javascript?

We have function available to get the back/past url using: document.referrer, so is there any way or function to get the "forward" url?
I just want to know if the current page has back or forward links. I have searched lot into the history and history-session but they are very limited due to some security issues.
Is there any way to get the next url?
Unfortunately there is no programmatic way of extracting the forward or reverse history from a browser. This is a security precaution. You can only trigger movement through the history and not view any of the entries.
A similar question...
How do you access browser history?
To confirm W3C states under "5.5.2 The History interface" in the following specification http://dev.w3.org/html5/spec/history.html#the-history-interface
"The actual entries are not accessible from script."
Edit and I would add that this is the only place that the information is available. If you are developing an extension you may be able to track urls yourself by storing the current url in storage otherwise you are out of luck.
You cannot read the history object. There is no way for your script to know which URL the forward button will lead to, or if it is available at all.

Show recently visited html pages by any visitor

I want to know how to show a recently visited pages' list with only html and javascript code.
I have a website. It has 100 html files and one html (index.html) for the home page, the others (1.html, 2.html ... 99.html) are sub pages. I want to show a recently visited pages block on my home page. I am trying to not to use php, asp or any other server side languages. Is there any way to do it? Thanks.
Edit1: Thank you for your replies. But it seems I did not make myself clear.
I want all visitors see the list, and the list will not only show pages that he/she has just visited, but all the recent pages that have been visited by any visitor.
I would look into using HTML5 Local Storage
It's essentially a DBMS stored right on the user's browser. Of course, it's not supported in IE < 8, so if universal cross-browser support is a requirement, this might not work for you.
Save a cookie on the user's computer. Generally, you have something like this (pseudocode):
read cookie
parse cookie
add current page to list (and probably delete old items)
save cookie
create list from data
Its possible to use javascript local storage or css a:visited if you want to create that list for just one user: the viewing user.
You cant share the list with other users.
Try tjis with the javascript history object. Check the link below. With the history object you can access the recently viewed pages and manipulate them. But if the user clears the cache then the data is lost.
http://www.javascriptkit.com/jsref/history.shtml
You could use cookies to store which pages a user has visited already.
http://jquery-howto.blogspot.com/2010/09/jquery-cookies-getsetdelete-plugin.html

Show all bookmarks using javascript

I'm trying to list all of my bookmarks using Javascript. Is there any way that I can accomplish this? Thanks in advance for any help.
In web design, there are some limitations due to security. Such as this, javascript would have to read your web folder on your computer and display the information from your computer. That would be bad security wise.
Use social bookmarking, and update it when you need to.
The only way to show your bookmarks is though xul aka an extension if this is what you want then look up places api. Places is a sqlite database located n ur profile folder.It's name is places.sqlite
If you use Firefox, there is a file called bookmarks.html in the profile folder. You can open this file and insert some JavaScript.
But as mentioned before, you can't (for good reasons) not access the bookmarks directly using JavaScript from any page.

Categories

Resources