Elliott
Elliott

Reputation: 5609

JavaScript problem toolbar=no

I have a simple logon page. When the user is validated, the window navigates to a new page. The javascript is window.open('http://www.google.com',"mytest",'toolbar=no'); My expectation is that when it navigates away from our logon page and opens the google site that the back button would be disabled. But it's not. Does anyone have any idea why?

Upvotes: 0

Views: 429

Answers (4)

Elliott
Elliott

Reputation: 5609

This is what worked for me. Instead of disabling the back key. I listen for on unload event. I then write the following in javascript:

window.onbeforeunload = function () { return "You should not press the back button while in this application. If you continue, your work will not be saved and you will need to log back in."}

Java Script pops a dialogue box with OK and Cancel options. If the user clicks cancel. The application stays right where they are. The script is embedded within the tags. For me this is the ideal solution. I found this at

http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript

Upvotes: 0

Adam Hopkinson
Adam Hopkinson

Reputation: 28795

This is bad practice - what happens if the user has javascript disabled? If the browser prevents the js from removing the toolbar of the main window?

Instead, amend the logon page to detect whether the user is logged in before showing the login form. If logged in, show a message saying so instead of the form - that way, a user clicking back won't be a problem.

I find it very annoying when a website messes around with my browser window, and generally don't come back.

Upvotes: 0

Parrots
Parrots

Reputation: 26902

I believe the option your looking for is 'location=no', as that hides the address bar and therefore the back button too. The toolbar is things like favorites/etc.

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 416059

It depends on your browser. Ultimately, all you can do with javascript's window.open() is tell the browser what you'd like it to do, but it's not obligated to do it. Browsers can and do ignore some directives based on user preferences.

Upvotes: 1

Related Questions