Disable browser "back" button [duplicate] - javascript

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Disable browser's back button
How can I disable a browsers back button, in an asp.net mvc project. Can I use java script for this ? or is there any other ways to do this ?

This has often been discussed on countless threads, the most exhaustive article is here and why it always will not work.

A website should not try to cripple the browser, but instead should work inside the browser-page system of the web. There are good reason for not wanting the user to click back (re-POSTing data, especially financial transactions and the like), but rather than forcing them not to, your website should handle these gracefully. Using a good framework like .NET leaves you a lot of great options for keeping your site stateful even amid the stateless web. Write your code to fit the browser, don't make the browser fit your code (like the ridiculous no-right-click javascripts of yesteryear).
That said, thankfully there is no way to do this, and even if there were, it could always be disabled on the client side.

I would have to assume it is impossible. That would be a big security issue on most browsers. I don't even remember in IE4 when the most extreme things were allows, you being able to do it.

I don't think that you can disable the back button, althought there are some "techniques" like those described in this site: http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911/Disabling-the-Back-Button.htm

It is not possible to the disable the BACK button of the browser, but if you don't want the user to go back to a previous page then you can add this javascript function to your page:
<script language="javascript">
function DisableBackButton()
{
history.forward();
}
</script>
And call this function in body only..
Like
<form id="form1" runat="server">
<script language="javascript">DisableBackButton();</script>
---your page design----------
</form>

Related

Need to design a HTML Page with following specification [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have the following specification that I need to build, however I do not know where to start.
Here is the spec:
Create an HTML + javascript page that can be opened in any of the browsers (desktop only is what I expect)
The page should have a timer control that allows the user to set up some timeout, say, 10 minutes (or 2 days!).
When the timer fires, the page fetches some content from a webpage of your choice and displays it (do NOT redirect or open a random webpage. fetch the content and display it on the current page or even a messagebox / alert() is fine). Choose any page / content that is on the web. For example, fetch google.com's landing page and display its html code in an alert box.
There should be an on/off slider-like button that enables/disables the timer control. If the timer is ticking and the user turns off the button, the timer should be disabled. When the user turns on the button, the timer continues to count down from where is left off. (Hint: Download and use some javascript button control / timer control from the web. Do NOT use the standard buttons. I'd like you to use a custom control. Shouldn't be too hard to use one of those custom controls).
Use generic images available from the web. Searching online is ok but do not copy some existing project that does this or similar.
I kind of agree with the comments above. My answer would be to hire yourself a web developer. You can put an advert on here, or hire someone through services such as elance. The above is a simple job for a frontend developer, but unfortunately these forums are for questions/answers that form a knowledge base rather then a method to turn requirements into source code.
Having said that, this is how to achieve the above:
1) Any browser is a complex being, and when you say 'opened in any browser' are you refering to the top 5 most used browsers, or every browser. Every browser would include text & voice browsers, and browsers that run on any machine, including browsers such as the original IE and netscape ones.
This changes your code, as the old browsers will not react to html5 code, where as the common top 5 ones will. if you ask a frontend developer to build you a site, they are likely to build it within html5.
As HTML was around before the first commercial browsers, html is generally well supported, css is a different beast, but you haven't asked about that. Javascript tends to be well supported across the browsers, however older browser versions have slight differences in how they response (some different names for functions) and javascript can be disabled in most commonly used browsers.
To get over this latter point, you can use tags that show a message on screen if no javascript is found.
A hello world html page in html5 would look like this:
<!doctype>
<html>
<head></head>
<body>
<h1>Welcome to my HTML5 page</h1>
<p>This is a 'hello world' example</p>
</body>
</html>
2) To create a timeout, it's very simple, in your script, just write this:
<script type="text/javascript">
window.setTimeout(function(){alert('I have been triggered');},1000);
</script>
see this for more details: http://www.w3schools.com/jsref/met_win_settimeout.asp
Now the format of setTimeout is easy (a function, timeout time). The timeout time is in ms, so in the example about, it would fire after 1 second. For 10 minutes, it would need to be 600000 (600k ms) and 2 days would be 172800000 (172.8m ms). Please note that a timeout will only fire if the window is left open on your page.
3) To fetch code from another page is simple and there are multiple options:
you can import it using the html5 method:
http://www.html5rocks.com/en/tutorials/webcomponents/imports/
to hack this into your function you would do this:
function(){
// assume I have been triggered by the timeout
var link = document.createElement('link');
link.rel = 'import';
link.href = 'http://www.google.com'
link.onload = function(e) {...};
link.onerror = function(e) {...};
document.head.appendChild(link);
}
or you could use jquery (you'll need the jquery library to do this): https://jquery.com/
You could have some javascript
$(function(){
window.setTimeout(function(){
$("#publishedContent").load("http://www.google.com");
},1000);
});
and you would need a matching html element on the page like so:
<div id='publishedContent'></div>
There are some other ways of doing it as well, but you'll need to discuss these with your developer.
4) For custom controls you would be best to look at the various jquery plugins/themes (http://jqueryui.com/themeroller/). If you search for jquery UI themes, or look at Twitter bootstrap (http://getbootstrap.com/getting-started/#examples) you should get inspiration on what is achievable. There are plenty of examples out there: http://olance.github.io/jQuery-switchButton/
5) To acquire images, the safest bet to ensure that you have the copy-write is use a service such as getty images(http://www.gettyimages.co.uk/) or shutterstock(http://www.shutterstock.com) and buy the images. They are pretty cheap.

Edit opened HTML Page, with Javascript

I was looking into making Firefox addons, and I need some help.
Is it possible to edit an HTML page that is open in the browser with javascript?
For example:
User types in "google.com"
Addon is activated
Javascript changes contents of "google.com" to maybe say "Hello!" at the bottom.
Of course this isn't specifically what I want to do, but a push in the right direction on how to accomplish such a task would be great.
~Carpetfizz
From within a Firefox addon this is obviously possible as many extensions do this.
If you, however, simply want to modify the DOM and nothing else than I would recommend taking a look at greasemonkey. Loads of example scripts around to do this: http://userscripts.org/
And the added benefit, if written correctly they also work in Chrome and other browsers.
Yes, it is. You must find a tutorial about javascript DOM manipulation

Pinterest "Pin it" button breaking 'back' in Internet Explorer

I recently found out that in Internet Explorer (v9 at least), the "Pin it" button for Pinterest is breaking 'back' functionality in the browser. Right-clicking on it shows an entry like 'http://assets.pinterest.com/pidget.html' as the previous page.
Looks like Pinterest is adding an iFrame and IE is adding its address to the history. Clicking 'back' doesn't do anything. Is this a known issue and is there a fix for this?
well, as a temporary solution (other than removing the 'pin it' button), from reading their code, I believe (not tested) that you could add a part to the <script> call to disable logging, like this ...
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js" data-pin-do-not-log="true"></script>
This works but doesn't apply for me because I load the script asynchronously and I use a load command, so what I did was I copied the pinit.js file locally to the server, and changed the part that says
if(a.v.config["do-not-log"]||a.a.doNotLog===true)
to
if(a.v.config["do-not-log"]||a.a.doNotLog===true||true)
looks like it's doing some sort of log in an iframe.
I was having the same problem. I added the website to my list of restricted sites by going to "Tools", then "Internet options", then "Security". It seems to have solved the problem.
I've raised it with PInterest here https://help.pinterest.com/requests/884162
Thier response. Pretty much a brush off.
Hi ,
Information on how to add the Pin It button to your website or product pages is available here:
http://pinterest.com/about/goodies/
More advanced documentation is available here:
https://help.pinterest.com/entries/21101982
We regret that we're unable to provide coding support. Because issues with adding the Pin It button can be caused by conflicts with different parts of your setup it is usually best when someone that is familiar with your setup troubleshoots it. You may also want to try searching the web to see if others have had similar issues especially people that are using a similar site platform or language.
We request that you use our help articles to get the information you need as quickly as possible. If there’s additional information you’d like our team to know, you can reply to this message.
Thanks for writing and happy pinning!
The Pinterest Team
This was a temporary bug when we first pushed the new Pin It button and should no longer be an issue, since we removed the logging frame shortly after it was reported. Sorry for the trouble!

Is it possible in Flash to launch a JavaScript function (which uses AJAX) in a page that contains the Flash object itself?

Here's our goal: in a website, show a nice menu "à la" iPhone in Flash and when we click on a menu, show a part of the site "under" the Flash menu.
Two options:
create a page with the
Flash menu that has an iFrame and
with Flash, open the menu in that
iFrame;
create one page with a div
on its bottom, with Flash, launch a
JavaScript (if you have any better idea please tell me !) function that downloads via AJAX the desired menu.
My #1 objective is to have only one page. Ideally it would embed the Flash object and launch a JavaScript function.
PS: I hate iFrames. iFrames are evil to me.
Don't hesitate to correct my question to make it proper English !
Thanks,
Olivier
Yes, this is very possible using ExternalInterface in the Flash document. That link explains the whole process.
A bigger question is that it sounds like you are using Flash to duplicate an iPhone animation and I imagine (unless you are doing the "Flip" animation) that it could easily be reproduced with normal JavaScript animation, possibly with a library like jQuery or MooTools to help normalize browser differences. You can even do the 3D animations in Safari 4.
An older method that is sometimes still useful is the getURL method. A good writeup of the differences is here: http://www.psyked.co.uk/actionscript/actionscript-geturl-vs-externalinterface-when-why.htm. In general, ExternalInterface is preferred, but sometimes you want to interact with the page with a function that not defined.
Usage:
getURL("javascript:myFunction(arguments);");
As Doug said, you may be able to use a JS library to recreate the iPhone animations. This would have the added benefit of your menu being navigable for search engines if this is a concern.
An alternative to Doug's suggestion is the old 'fscommand()' function. In your Flash code, you put "fscommand('name', 'value');" replacing name and value with whatever information you want to fire out to the web page.
On the web page, you need to have a JavaScript function which listens to the 'FSCommand' event of the Flash object, like this (IE sample, see docs for other browsers):
function OnFSCommand(name, value)
{
// whatever you need to do with name & value
}
var swf = document.getElementById(name-of-my-Flash-object);
swf.attachEvent("FSCommand", OnFSCommand); // IE-only - see docs for other browsers

Hiding toolbar / status bar with javascript in CURRENT browser window?

Is there some way to hide the browser toolbar / statusbar etc in current window via javascript? I know I can do it in a popup with window.open() but I need to do it this way. Is it possible at all?
As per the previous answer, this isn't possible to my knowledge and is best avoided anyway. Even if a solution can be found, bear in mind that most browsers these days allow the user to prevent Javascript from interfering with their browser settings and window chrome, even when using window.open. So you've got absolutely no way of guarenteeing the behaviour that you're looking for and consequently you're best off forgetting about it altogether. Let the user decide how they want their window configured.
I believe this is not possible. And anyway, just don't do it. Your page can do what it wants with the rendering area, but the rest of the browser belongs to the user and websites have no business messing with it.
Marijn: ok thanks. This is for an intranet site and we display InfoPath forms as separate, no-toolbar, no-statusbar windows. This is a client requirement, I'm not trying to do evil ;)
To Martin Meredith, Luke, Marijn: thanks for your quick reply. It is now settled that it's not possible.
I agree with you all about this being an undesirable behavior, but as i stated before, this is for a bank intranet application where all users are running a tightly controlled, centrally-configured, customized and hacked to death browser they have no control over anyway, and the client actually wants this behavior for the application. It would be dumb and annoying to do this in a public facing/general website, of course. But sometimes we just have to get the job done :(
No. This would be a massive security hole if it were possible... not to mention annoying.
My browser wont even let you do this in popups... which can be annoying aswell!
You may want to investigate using an HTA (HTML Application).
It will render HTML pages with zero browser chrome, a custom icon can be shown on the task bar, and the entire "caption" can be removed. The last option yields a floating window without eve a close button.
For how I imagine your needs to be, you would want to start with something like:
<html>
<head>
<title>HTA Demonstration</title>
<hta:application innerborder="no" icon="magnify.exe" />
</head>
<body style="overflow: hidden; margin: 0;">
<iframe src="http://www.yahoo.com" style="width: 100%; height: 100%;"></iframe>
</body>
</html>
Save the above HTML into a file and give it "example.hta" as the file name. You'll then have a generic icon on your desktop which you can double click on to start.
<hta:application innerborder="no" caption="no" icon="magnify.exe" />
This change will remove the title bar when running the script. Press Alt-F4 to exit the script if you do this.
This will also only work with IE, however that should not be an issue on an intranet.

Categories

Resources