Saving URL to cookie and adapting to button - javascript

I'm currently looking for something to do the following:
scenario:
user clicks button on page 1-15 and navigates to page 16, user does several actions, and when clicking on a 'confirm' button, he needs to return to page 1-15 (whichever he was on earlier).
How could I do this? I was thinking to simply write the URL in a cookie which can then be read out and adapted in the final destination URL.
Or am I looking in the wrong direction? Some code examples would be helpful as knowledge is limited.

use sessionStorage.setItem('currentPage',1);.
then when you need to use this number just call sessionStorage.getItem('currentPage')

Related

hide an HTML form action url from the page source

Is it possible I hide an HTML form action url from user? I mean that user can't see it on the page source code.
I found this way , but in this way user can find that action from the page source!
In principle this is impossible, because the browser needs to know how to handle the form, and anything the browser knows, the user can know. Perhaps if you give more details about what it is you're trying to do, there is another solution.

How was this full URL found?

A co-worker took this url: https://www.rbi.org.in/Scripts/BS_PressReleaseDisplay.aspx which has month/year pagination via Javascript (see the elements on the right) and was able to give me this url:
https://www.rbi.org.in/Scripts/BS_PressReleaseDisplay.aspx?__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTg0MTg0MzQ2NmRk1lDKkbV9IbwhES0FyX%2BlSLhp%2FzA%3D&__VIEWSTATEGENERATOR=380F4D6F&__EVENTVALIDATION=%2FwEdAAiUUGGuo52vbcR6TOSGc2%2FnlK%2BXrsQEVyjeDxQ0A4GYXFBwzdjZXczwplb2HKGyLlqLrBfuDtX7nV3nL%2B5njT0xZDpy7WJnvc3tgXY08CYLJD%2BrfdwJAuBoVBISURIXWlx9xf1loRXvygROM%2FA1O%2BNHJounKCGGAHd04zzVhBPZz4BK5Wx46wqhV0iQkxGw1Nhr9A6c&hdnYear=2016&hdnMonth=12&UsrFontCntr%24txtSearch=&UsrFontCntr%24btn=
where I can replace the year after hdnYear and the month after hdnMonth with any year and month, and it will bring me directly to that page. I asked him how he did it, and he said "I used the Network tab in Chrome dev tools." That's about all I could get out of him.
Does anyone know exactly how this is done? For example, I'm now trying to discover similar way to get the actual url for each page of this site: http://www.ojk.go.id/id/regulasi/otoritas-jasa-keuangan/peraturan-dan-keputusan-dewan-komisioner/Default.aspx by looking at the Network tab as I change pages. There is nothing I can see in there that's similar to the above example.
This is how it was done for the rbi.org.in URL you've mentioned
Open Chrome and go to the URL you've given
Right click on the page and select Inspect
Click on the Network tab.
Click on one of the year/month links on the website (the pagination you referred to)
In the Network tab, you'll see a list of GET/POST requests being made by the client (ie, the browser) to the server.
In the Filter box (on the top-left of the Network tab), type in the search filter method:POST.
Click on the entry in the Name column. This will open up more details about the POST request. Scroll down to the section titled Form Data.
Click on the view encoded button in the Form Data section
These are the parameters your friend included in the URL. You'll notice hdnYear and hdnMonth also listed in there. The URL your friend gave can be obtained by clicking on view source
Well I can't really tell you how to exactly reproduce this in the site you're trying to, but I can tell you what your co-worker did.
In the page https://www.rbi.org.in/Scripts/BS_PressReleaseDisplay.aspx:
Open the network tab in dev tools, clean the log if theres anything there.
Click on a year and month
On the network log search for BS_PressReleaseDisplay.aspx in the "Name" column and click on it
Inside the Headers tab go to "Form Data" and click on "view source"
And thats it, theres is the URL parameters that your coworker gave you, you can try doing this on the site you want to reproduce it clicking on another page and searching for Default.aspx, but you'll have to figure out what does each parameter means to find which one is the page number or whatever you're looking for (check it in the parsed view for easier reading).
Screenshots:
http://prnt.sc/emsl2w
http://prnt.sc/emsm2z
Hope this helps you.
The URL he sent you, has URL parameters/query-strings that, is read by the server which then sends you the selected pages.
So basically the servers pics up the request and reads these paramters which then most likely is parsed into a method of some sort, querying a database then returning the result for you.
If your the owner of the linked website, you can implement such solution, otherwise you´re stuck since it requires coding on the backend.

How to stop triggering introjs after first walkthrough?

I'm using introjs.
But when a user ends the intro, then refreshes the page, introjs starts up again.
Is there a way to only show a walkthrough once per user?
For example I have it where when a user first signs into my website - introjs will popup. I only want it to pop up for that initial welcome.
Potential Solutions
Maybe there is a way to trigger introjs via the create action like one would with a flash message?
I could replicate all my header, sidebar, and challenges section code into pages/tutorial.html.erb and make a route www.websitename.com/tutorial, but then that would be a lot of code to duplicate and then whenever I change something in the site I would have to change it in tutorial too.
Is there a way to adjust this javascript method in application.js to trigger only once per user $(function () {
introJs().start() })?
I just use data-intro="" for each step of the walkthrough.
You want your application/webpage to remember that the user has already gone through your tutorial.
There are a few ways you can do that. For a start, you can use cookies or localStorage
The gist is that after the user finishes, or otherwise exits your tutorial, you can store a descriptive value to the user's client, by using one of the above methods, and on page load you should first check if this value exists and act accordingly.
EDIT: As mentioned in comments, you will need a server side approach as well.

How to complete a link with user input

I'm completely new to javascript, and I'm trying to get a script to complete a link with a user input.
I.e. I have a common base url like http://www.mystuff.com/ and I would like to create a form to let the user reach a specific page if he knows the exact url. I need a basic input field where he can write a string (like h5mlf4) that will send him clicking the submit button to http://www.mystuff.com/h5mlf4.
I've found this script on this page which is pretty close to my needs. I've tried to modify it, but I don't know how to do both the actions (add the user's input and launch the link) on the same button with an all-in-one action. I don't want to create the link on the page, I simply need it to be immediately used.
I hope to have been clear, and thanks to everybody will take care of this.
Do
window.location = "http://www.google.com?q=" + userInput;
to "click" that link (i.e. go to that link) for the user.
Doc for window.location >> https://developer.mozilla.org/en-US/docs/DOM/window.location

Use jQuery to append star to menu item if the linked page's content has changed since last visit

I would like to create a similar effect to Apple's Safari 4 Beta Top Sites page -
when when you view it and a page's content has changed since you last visited, it displays a blue star in the top right hand corner to notify you.
I would like to do the very same, but only within my website and instead of an image I would like to append a '*' or some other character to the menu item's link.
I'm sure you would use the jQuery Cookie Plugin, but my scripting is not that advanced and I do not know how to dynamically change the cookie's content. Have I explained properly? How would I do it?
Many thanks in advance
Server side:
Read the website f.ex every minute and save the timestamp if changed content.
Save the users' visit timestamp to the page
Ajax:
Check if the websites update timestamp is newer than your visitors' timestamp, if yes make the star class visible, when the user clicks on the link, make the star disappear and update the users timestamp.
--
Showing a star or an image or whatever with Jquery is not the big deal here, it's a oneliner, the complex problem is to detect website changes, because minor changes can occur, but the main content could not change. The easiest way to do this would be if the website provides rss, then there's probable that the important new content will be published via rss.
You're asking a very vague question. Have you even attempted this? Please try it first then ask for help along the way.
Also, this is not something you necessarily need jQuery for. You could do it completely on the backend. But it's hard to say which solution is best for you without know anymore details.
I guess I would recommend using php and storing the cached page into a db (in other words the user would have a "fav pages" account) then when the user visits the "fav pages" webpage, you would fetch all the users favorite pages and compare it to what has been stored in the db. But for certain pages (for example if they have a date/time string), it would be very difficult to tell if the change was something the user wants to know about. Probably you would need to create a complex algorithm to decide what change is good change and what change is just certain website features.

Categories

Resources