Is it possible that the html page loaded, cannot be refreshed or reloaded by the user
Thanks..
No, and you shouldn't try to do this...it breaks all the users expectations of what a webpage does.
Whether it's code or behavior, when you're having trouble doing something, it's usually because it hasn't been done or hasn't been made easy...stop to ask why that is, and often you'll find there's a good reason.
The onbeforeunload event could be used to detect a situation like this.
I think this is what SO uses when you write an answer and then want to leave before you post it; it asks you if you are sure.
Is that what you want to use it for or what?
Related
Is it possible to have a radio button in an alert box?
The requirement is, not to use any modal box, that why we just think if it's possible with alert box or confirm box. then we can good to go.
Any help will appreciate.
Sample Screenshot is below.
i don't guess. i know that this is in fact impossible.
the reason is simple:
alert(), prompt() aswell as confirm() were part of html + js since js exists.
they never got deprecated though they break the asyncronous flow of javascript.
this is essentially why they only allow you to play around with strings.
they were never intended to be feature rich.
they were actually invented out of the blue because the inventor (Brendan Eich) thought they'd come in handy. (wich at that time was more than enough for everyone)
they are by design blocking operations and should be avoided as much as possible.
to get around them simply create a so called modal dialog (thats basically a <div> with position: fixed above the pages content.
benefit:
you can easily make it appear as you want and you would not break any network connections or behavior of your application.
PS:
don't use w3schools as reference for learning or anything else.
they are a low quality database. you should look stuff up on mdn or other sites but should seriously avoid w3schools since it's not feature complete on any topic.
keep in mind this is an opinion.
It is impossible to use radio inside of alert window.
Message parameter in window.alert(message); has a string type and you cannot put Object or HTML there (will be transfomed to string).
Do not overuse window.prompt() Method , as it prevents the user from accessing the other parts of the page until the box is closed.
Window prompt Usage Note
Is there any way to do something like this: $(window).on("hashchange", doSomething); but detect document.location.search change?
This was already asked in On - window.location.hash - change?. In a nutshell, there is no perfectly clean way to do this in JavaScript; you would need to be checking the location every now and then. Some frameworks and libraries will give you a nice abstraction layer over this but internally, they just keep polling the location.
Unfortunately, Lucas' answer is incorrect - you can use the JavaScript History API to modify the current URL without reloading the page.
The hash and the search tag are having different implementation. When the search string got changes the whole page got reloaded but not in the case of hash. So if you want to do some processing on href change then you can use the onbeforeunload event handler.
You can use the beforeunload event to trigger your code to run prior to navigation... If you need something more specific (e.g., only navigations initiated in your code), then I recommend that you factor out code changing window.location into a separate function, and add a hook for your custom logic.
For better understanding you may want to look at Ben Nadel's post in regard to doing this, it may be exactly what you're looking for.
Differently from what happens with hash, if your search value changes due to a user's action, your page will get reloaded. Therefore, your option would be to use the onbeforeunload event:
<body onbeforeunload="return myFunction()">
http://www.w3schools.com/tags/ev_onbeforeunload.asp
I have a javascript alert asking the user to insert a password. When user presses button, I will do an AJAX call to check the password. This could generate another alert with the response (if it was accepted or not), but I wonder if it is possible to have the AJAX response change the text of my first alert? Is it even possible to override the alert button's default not to close itself when clicking "okay"?
I think generally you should try and minimize the use of alerts in your web application. They are very obtrusive and annoying. Generally people just update the DOM to display user information. An alert is for something more unique and important than somebody just mistyping their password.
EDIT:
As other people are pointing out, you should use modal dialogs instead to have behavior as you specify.
I'm quite sure you can't do that since the way the alert is constructed and displayed is different in each browser (just look at mobile browsers). I think you'll safeguard your sanity longer if instead you use modal dialogs.
Being a blocking function, alert() is an abomination in itself, and owing to that would thwart the very thing you are trying to do.
I'd like to add an onbeforeunload javascript, asking the user to bookmark the page (there's a small button in the header for that purpose).
The problem is, no matter if they'd like to bookmark it, it's pointless and annoying after running once.
So, what's a generic solution to stop a javascript from running more than once?
Thanks,
Emilia.
EDIT:
Yes, I guess an onload event would be more appropriate?
I don't really want to add "big red buttons"...
Any basic example how a IP validation + script would look like?
I would say it's already a bad idea to use a pop up when the user wants to exit the page even if it is only once, it's annoying and obtrusive. I suggest you place a big button on site itself if you want to call the visitor to an action, bookmarking in this case.
If you still want to though, you should use IP validation and not cookies, cookies are temporal, they can be removed by the user, and visitors will not like to be presented the same suggestion over and over.
Is there a better way to collect data on how many visitors don't have js enabled. My idea was to add a hidden value at page load with js. If it works then js was successful. But looks like there's no way to actually read it back to know if it was successful unless I do some kind of a page reload, but now it gets complicated (I have to delay whatever operations that were about to happen, etc. so as I said gets complicated). Any tips or ideas on this? I'm sure there's a better practice way than mine.
I should add, if there's already a ready-made solution for this, please let me know, I'm not really interested in reinventing the wheel :)
A good way to do this is use a <noscript><img src="track.php" width="1" height="1" /></noscript>, and that will allow for browsers without javascript to pull a tracking image and then the server can get the Useragent and IP from that tracking image.
You can't know in advance which technologies the user is using client-side, so the only way to know for sure is after the first load. Even so, he might disable JS after the first page load and you're left running with a different scenario.
In fact, try it here in SO: load a page with JS enabled, then disable and reload. You'll see a big red banner at the top telling you this page works better with JS enabled.
Bottom line: you should never rely on client's technology, unless you really want to limit the people reaching your site. If you want to reach the most number of people, you should code as if they had every technology, and none at the same time.