Making a div appear on button click (PHP) - javascript

I am a first poster here so please excuse my noob-like behavior.
I have a button on my website that when pressed should disappear, and a form should be echoed out in its place without a page refresh.
I have easily achieved this with JavaScript / AJAX, but if JavaScript is disabled, I still want the button to do it's task.
My question is: Can I do this only using PHP, WITHOUT a page refresh?

Cannot comment or I would have but the answer would be no. PHP is server side so the only way for it to update a view is to reload to a new page. Also, I would think it is very unlikely to run into a situation where JS is disabled these days.

Not in a way I think you'd want to do it, but you could use an iframe that contains the button. The button would be a link or form submit and the navigation would happen inside the iframe to your form. This way, only the iframe is refreshed, but the full page remains unchanged.

You can only aciehcve this using ajax. You can force your users to enable
javascript noscript tags
<noscript>
<p>This page requires a JavaScript-enabled browser.</p>
</noscript>

Related

HTML5 iframes usage to skip loading intermediate html

I have a HTML page which I want to display on browser. This is a login page(https://localhost:9000/login). Before loading this over browser page I want to hit another url which gives me another html page . This url is basically to kill the existing sessions.(https:xyz)But this also redirects me to another page which I don't want to display . I want to remain on login page.
I think this is possible using iframes. I am newbie to iframes. Any pointers on how to achieve this?
That's a local link only viewable on your computer.
So you want to load another page, before the login page? If you want to kill existing sessions you can use sessionStorage for that.
There are a few things that don't make sense with this, but it's your project. like you want to redirect to another page, but don't want that page to display. That makes no sense to me.
You want to remain on login page, but when you login, you want to get another html page in the login page?
iframes are probably the worst thing in the world imo... you got so much going on here, but can simplify this so much. A login page to an inner page and then you go from there.
There are a number of ways to achieve the end means here, sessionStorage being one. Just search around here for answers, you can find a ton of them.
Good luck!
iframes have been removed from HTML specifications, you cannot use them in HTML5.
Use attribute target="_blank" in the <a> of this url. It will open in a new tab

jQuery AJAX back button after changing html

I know there are many questions about jQuery + Back button issues, but it seems that they're trying to maintain history features when clicking the browser back/forward buttons.
My question is that when clicking the back/forward button, how can I load ajax-affected html page?
For example,
In index.html, dynamically remove all "div" elements from the list using AJAX (jQuery.post()).
Press the browser back(or forward) button to go to newpage.html.
Press the browser forward(or back) button to go to index.html again.
PROBLEM: the html page contains the deleted "div" elements.
How should I load index.html with no "div" elements after step (3)?
I'm currently using jQuery and Django as backend.
Thanks!
Use the jQuery history plugin to encode the application state. See their Demos page for examples of how to do what you want.

How to redirect inside jquery tab using javascript?

I've just got this jquery form working, it's based inside a jquery tab, and on clicking the submit button, it submits to a mySQL database without leaving the page or anything. Now, though, I want it to redirect the user, without making them leave the tab, to a different page inside the same tab once they've submitted their details.
Does anyone know the Javascript code to do this?
Thanks!
If you're trying to load a new page into the DIV where your form was, simply call
$('#idOfDivWithForm').load('newpage.php');

How do I detect the client has javascript turned on/off from Rails?

I don't want to deal with users who have javascript turned off, so I want to just prevent them from using my application. I want to detect if the user has javascript turned on so I can redirect them to a page that tells them they need to use javascript. I'm sure its in the request header. Anyone have any ideas how I can do this?
The noscript tag is the easiest solution, though not exactly whay you're looking for.
<noscript>Get outta here.</noscript>
Do you really need a redirect at all? Put the message in a <noscript> element, and it will only be displayed to those it applies to.
You can't. The server has no idea what the client has enabled. You can't even "detect" if Javascript is disabled from the client (because what would you use to do so?).
You can use tricks to show content when Javascript is disabled (for instance, a <noscript> tag, or using Javascript to hide content that is meant for JS-only).
There is no way to detect JavaScript on the server side. However, you can use a NOSCRIPT tag to display a message indicating that your website requires JavaScript.
For an example, turn JavaScript off in your browser and load a Stack Overflow page. There'll be an obnoxious red message across the top of the page warning you that the site works best with JavaScript enabled. You can examine the Stack Overflow source code and CSS styling to see how they implemented it.
If you really want to deter non-JavaScript users from using your website, you could put your message in a div inside the noscript tag and expand the div to cover everything on the page.
You only need html:
<noscript><meta http-equiv="refresh" content="0;url=http://example.com/use_js.html" /></noscript>
This of course won't prevent the server from serving content, it only will output this meta refresh tag, which will be parsed (and executed by redirecting the user) by clients that got no javascript or javascript disabled.
You could have a landing page with a snippet of javascript that runs and redirects to the real railsy landing page, or perform an AJAXY call to get the data you want to show the user. This would positively require javascript to be enabled to continue.

solution for popup page as modal

I was using window.showModalDialog() but doesn't work on all browsers.
People recommends me jquery, thickbox and also this contact Example
but the problem is when i submit the page, server will send me another page, and that page will replace my original page!
so actually it doesn't fulfill my requirement.
My requirement is on button click modal page should open and it can redirect to other page on same window without disturbing my original page and when I close My original page get reflections.
So is it possible?
Sounds like you need a simple html target="_blank" in the link to the other page.
http://www.htmlcodetutorial.com/linking/_A_TARGET_95y98y108y97y110y107y.html

Categories