MVC Form - Clear ModelState on Back in Browser - forms

I have searchbox in my web app.
I am curious how to clear ModelState when user hits back button. The page retains the 'text-input' from the search results page when the user hits back and goes to home page, which also has a search box.
Before Posting the ques did some initial research here.
I checked similar question on StackOverflow and saw that ModelState.clear() helps you clear he info. But when the user hits "back", the controller does not get called (obv!!) thereby Clear() does not get called.
So what is the best way to get around it.

One possible way would be to use javascript and clear the value when the page is loaded. For example with jQuery:
<script type="text/javascript">
$(function () {
$(':text').val('');
});
</script>

Related

Article open in modal window after a user click on facebook share link and come back to your site

I think I need your help here... On my site, I've done all the articles open in modal window by clicking on the link "read more" that exists in every article.
Also, each article has a button that shares this article on facebook.
But, when the user who will see my article on facebook, click this link to read the article, it come back to my page, but the article (logical) not open in modal window!!!
Is there any way, in the "return" of the user on my site, after having pressed the link of facebook, automatically open this article in modal window? Or, if the question above can't be done, is there any way by customizing the link I send to facebook, to set it in the "return" of the user to my site, after having pressed the facebook's link ofcourse, to show the article in intro view and not in full view?
Thank you very much for your time!
I'm using modal windows in my website and I utilize the following HTML code to open an article in a popup:
<a class="modal" rel="{handler: 'iframe', size: {x: 680, y: 370}}" href="yourarticleid=759&tmpl=component&task=preview">Open a link in modal</a>
The method above uses the native function for creating the modal window and calls the article you need to display. However, since Facebook formats all posted links I don't think you'll be able to include the crucial piece of code (below) that triggers the modal window.
class="modal" rel="{handler: 'iframe', size: {x: 680, y: 370}}"
Here is a kind of solution, an idea in other words, that make your articles open in modal window, after a user click on facebook share link and then come back to your site.
In my case I did this...
To open modal windows in my site, I am using the extension modalizer from nonumber.nl. This extension adds something like that &ml=1 at the end of article's url. The link that comes from facebook don't contain this &ml=1 at the end. So...
1. First of all, in to my article's content, I should include modal's behavior.
2. Then, I should make my code check if the url has this &ml=1 at the end or not.
3. After, I should decide what my code will do in those two cases. So, I want to do nothing if &ml=1 already exists and I want to open facebook's url in modal window if &ml=1 doesn't exist. I also want everytime that I close my modal window to load index.php, else user will see my article on frontend view.
Here is the code for all this:
<?php JHTML::_('behavior.modal');
$url= 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if (strstr($url, "&ml=1")){/* Do nothing */}
else {?> <a class="modal" id="modalWindowLink" href="<?php echo $url ?>"></a>
<script>
window.addEvent('domready', function(){
window.addEvent('load', function(){ SqueezeBox.fromElement($('modalWindowLink')); });
});
SqueezeBox.addEvent('onClose', function(){ window.location = 'index.php'; });
</script>
}
<?php } ?>
If you have any better idea, or if you see something that could work better in other way, please let me know!!!

form textbox - keep focus during page load

On my homepage I have a form with a search textbox. If you click on the input and start typing when the page in still loading, something steals the focus so you have to click back in the input textbox.
Is there a way to prevent this from happening? Do I need to find what is stealing the focus?
Sounds like one of your scripts is setting something to focus on load.
Put this at the bottom of your HTML right before </body>. Your console will show you the HTML of the item that is gaining focus.
<script>
$(window).load(function() { // NB not document ready
console.log($(':focus')[0]);
// alert($(':focus')[0]); // if you don't know what console is
});
</script>
Hopefully there will be an ID in the element that you can search your script for, or enough clues to let you find what's being told to focus on load. Then you can remove/alter that line.
Addendum
It turns out this is the culprit
$('#f input#livesearch').clearableTextField();
That clearable function is only ever going to be required if the user uses that field, so let's make it contextual, i.e. only when it's given focus, make that function available. This should stop the naughty plugin stealing focus.
$('#f input#livesearch').on('focus', function(){
$(this).clearableTextField();
});
It's generally best to write contextually - you'll find pages with dozens of binds and "live" events being set up on onload, but they are rarely used. If it's something that doesn't need to happen until the user does something or until you can tell a user is about to do something, write it that way.

OpenCart 1.5.3 IE cannot work payment method in checkout page

The "continue" button on the checkout page under delivery details doesn't work. But the ‘billing details’ continue button and all other always seems to work. When click on the button, the waiting GIF is loaded and nothing happen.. When I comment out below script then it seems to be fine in all browsers.
<script type="text/javascript">
<!--
$('.colorbox').colorbox({
width:640,
height:480
});
//-->
</script>
I want to show the Terms & Conditions in popup..I didn't get popup when I comment the above code and it shows in another page.
I had a similar problem with the tabs. I resolved the issue by placing the call in a document ready jquery container.(http://api.jquery.com/ready/)
The problem for me was that the JS in IE was trying to load before the element had rendered.

How can I hide like button or div from Firefox?

I am building a web page and I have included Facebook's Like button. Works great in all browsers but not in Firefox. When clicked in Firefox, it creates an endless loop of opening and closing a facebook login window. This is a known issue that Facebook isn't looking like it will correct anytime soon.
Can anyone tell me what code I might write to hide the like button (or a div containing the like button) from Firefox only? I've never written code to detect a browser and then have my site function a certain way. Not a javascript guru here. Thanks!
You can do this using the navigator javascript object, but it sounds like you have deeper problems if the facebook like button is causing an endless loop of window loads. You most probably have other errors in your code. The button should work fine in firefox.
Here's how to text for firefox using the navigator object,
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
// user using firefox
}
This code parses the userAgent string, the string that defines the user's browser, of the navigator object. It looks for a string of the format Firefox/x.x or Firefox x.x.
This should work for you
<div id="likeDiv">
my div
</div>
<script>
if (navigator.userAgent.indexOf("Firefox")!=-1)
{
// Remove the element from the dom
var Node1 = document.getElementById('likeDiv');
Node1.removeChild(Node1.childNodes[0]);
}
</script>
Hope this helps

How can I block until the user hits the hits "close" on FB.Connect.logout?

I have some HTML that looks like this:
<a onclick="FB.Connect.logout(function() { window.location = '/'; });">
link text
</a>
logout brings up a modal that tells the user he's logging out of Facebook and has "close" button on the bottom right. Unfortunately, the browser proceeds to '/' per the callback function. How can I stop that from happening so that the user has enough time to read what's in the dialog?
Also, the close button seems kind of useless since it gets blown away once the callback gets called, so I feel like I'm missing something there...
PS: This seems like a long shot, but I'd like the user to be able to stop the log out process if having to log out of fb changes his mind. Is there a way to do that?
Have you tried the pound sign? # This tells the browser to redirect to an in page anchor..and doesn't generally redirect anywhere. This might work for you!
If you're performing an action rather than going to a location, I'd recommend using a <button> element.
With Prototype:
<button id="button-logout" value="Logout" />
function finishLogout(isLoggedOut){
if (isLoggedOut) {
location.href = "/goodbye";
}
}
function beginLogout(){
//preparation if necessary.
FB.Connect.logout(finishLogout);
}
$('button-logout').observe('click', beginLogout);
It's always better to have your events in the javascript rather than inside your tag's onclick. And, although I did make two seperate functions, it's easier to revise and reuse them later, and you can always minify them if you're looking to optimize.