Redirect html link based on time - html

So I have a website which has a link to a form - within the same domain name. However I only want the form to be accessible during specific times of the day i.e. 2.30pm-4pm and 8.30pm-12am. Outside of these hours, it should automatically redirect to another page if the link to that page is clicked. I.e. it should divert whenever that page is being accessed out of hours if that makes sense.
Any ideas as to how I would go about doing this?

This cannot be done with pure HTML as HTML is static. You could do this in a variety of languages depending on what your server is running.
A Javascript solution could work, but the client could get around it if Javascript were to be disabled so I would recommend a server sided solution (PHP, Node.js, PERL, whatever you use etc.)

Related

Distribute a strictly client-side app as one file

So I am trying to develop a browser based 'app' that is similar to a catalog. The user can place orders and view items on this page. Right now it is made up of an HTML page, a CSS sheet, some Javascript and some PHP. Unfortunately this app can not be hosted on a server, and will the files will be directly sent to the user.
I don't want to directly send all of my code to the user, I want to make things simpler (and more hidden) by compiling all these scripts/sheets into one file that the user can just open in their browser.
I've considered doing the scripts and sheets inside inline HTML, but inline script have too many drawbacks and are bad practice.
Any suggestions on how to accomplish this? Should I not worry about it and make sure to instruct the user just to open up the HTML file?
Thanks.

Serve up different HTML pages from same script?

I am trying to have a single GAS project that changes its UI by serving up different HTML pages based on what the user clicks. I cannot figure out how to serve up different HTML from the script, replace the current browser page and retain state. Any help appreciated. Thank you.
I use two options:
Have a main page which has buttons or text areas with onchange set to a function which calls back to the server side and gets new page data, then replace the current page or a portion of the page, with the new page.
Pass parameters in the URL and have the server side doGet() parse the parameters and branch to load a given page based on these values.
I have used a combination of both of these effectively. Basically I have a div which has my "menu" and a div which is the section to be replaced. My menu changes and then data is sent back to the server to get the dynamic body. The HTML is returned and then I replace using innerHTML.
In the same code I offer the ability to pass menu values via the published URL. This allows me to go directly to some values if I so choose as I have a Google Site where we embed the script into pages and the menu selections may be specific to that page. It allows us to use an iFrame to show the web app and go directly to the pertinent interface.
With google.script.run you can run any script on the server from the html page. By communicating with the server you have access to PropertiesService which gives you the capability to store information between pages. Personally I like the HTML Service createHtmlOutput(html) because I can edit the html without having to edit a separate page.
I decided to answer your question here so that I could use the code section.
Question:
I am actually looking to avoid manipulating the HTML and serve up a
completely different HTML file stored in the project. How do I make
the page call the script again and replace itself with the new
content?
We I'm guessing that completely replacing the page is not really what you want because the user will suffer a page refresh. But you could create divs like this:
<style>#R01{display:none;}</style>
<div class="replaceable" id="R01"></div>
If you put all your replaceable content in divs like that then you can request content from the server via calls like this:
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.getConversation();
and put the new content into the appropriate divs and then change the css with another pair and turn the old content off and the new content on. Thereby avoiding a page refresh. Don't forget to save the old data into the PropertiesService first. So I don't think changing the entire page is the way to go but I could be wrong. I think just changing some of the internal content will avoid the need for a total page refresh. If you want to change images you can avoid another download by using CSS Sprites

Redirect between html, jsp without changing the URL

I am planning to design a web application with multiple HTML and JSP pages. The first page of myapp (index.html) loads up with the url
localhost:8080/mywebapp
without an explicitly pointing it to
localhost:8080/mywebapp.index.html
because web-xml has index.html in its startup script. Thats perfectly fine!
But how to toggle between multiple JSPs and HTMLs that are in the web app keeping the URL constant
localhost:8080/mywebapp
The user should not be knowing the navigation pattern when he is using the web-app.
Ideas on any frameworks or implementations are highly appreciated.
Thanks
Leaving aside the fact that you shouldn't do this, essentially what you have to do is bypass the standard routing method of your application.
You can do this one of two ways.
1) Use Ajax to call all the different URLs you need from within a single page. This will give you the single URL you're looking for though it doesn't of course prevent anyone from trivially working out what the actual navigation URLs are and unless you build a single page app and do some really evil interdependencies finding your navigation is trivially easy.
2) Your second option would be to create a single servlet which takes parameters which identify which part of your application you want to use. If you really wanted to be horribly evil you could hash those arguments with some form of per user short duration cookie so that even if they identify the actual web calls you're making running them manually won't actually work.

HTML Form appearing on button press

I am a newbie to web development so sorry for my stupidity. I am actually creating a local website and I wanted to make a user profile page on that website. What I want to accomplish is that the profile page should be not be editable in the normal use case but when the user presses the Edit button (like in facebook), the fields become editable and a save button appears (basically a form but without reloading the page or any server side work). The user then updates the fields and saves. The save request will be sent to the server to update the database (can that somehow be done without reloading the page too ? i see facebook page does not reload when you edit and save).
So that is it. Waiting for a reply.
P.S. I think some javascript code will come to my rescue.
This is a very general question, so I can't do anything but give a general answer. I would highly recommend you learn jQuery.
jQuery makes it easy to manipulate the HTML and CSS from Javascript - which you'll need to do in order to show/hide the content and the forms for editing the content (or otherwise manipulate the code on the page in order to achieve what you want - there are various ways to do this, adriano's comment on your question lays out a good solution).
The specific part about sending such requests in the background is called AJAX, and jQuery has support for that too.

Getting iframe URL using Scala/Lift

all. I am working on a Scala/Lift web application that uses an iframe to display content from another web application hosted on the same domain. Is there a way to access the URL of the child frame's currently-displayed page? The suggested solutions found for the general problem typically use Javascript, but I would to like accomplish this with Scala if possible.
Thanks!
I don't believe this would be possible, presuming you are trying to read the current page that it is on rather than the page that is sent by default.
If you are trying to read the current page it is on then that would necessitate interaction between the server and the client, meaning you would have to use some javascript. If you are trying to find the page it was on originally then that should have been set earlier in your program so you will be able to just store that value in a variable and access it later.
If you clarified which you were trying to do you might get a more complete answer.