473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Conditional option in push-button?

Hi all.
Can a conditional be applied to a button?
I want user to go back if they have come from a previous page
or to simply close window if they have not. Tried this but no go!

<INPUT type="button" value="CLOSE WINDOW" IF history.
onClick="history.back(-1) else onClick="javascript:window.close();">
Sep 7 '06 #1
1 1574
Richard Rosser said the following on 9/7/2006 7:17 AM:
Hi all.
Can a conditional be applied to a button?
I want user to go back if they have come from a previous page
or to simply close window if they have not. Tried this but no go!

<INPUT type="button" value="CLOSE WINDOW" IF history.
onClick="history.back(-1) else onClick="javascript:window.close();">
The best you could do is to check document.referrer to see if they came
from a linked page or not. You can't check the history trail as it's a
security breach.

onclick="if(document.referrer){history.back(-1)}else{window.close()}"

But it is still fraught with errors. If I right click a link and open in
a new window/tab then the referrer will be empty and the script would
attempt to close the window. Yet, since the window/tab wasn't opened
with script you will get the "Script is trying to close a window...."
message in IE and an error message in the Console in Firefox.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Guy Hocking | last post by:
Hi there, I am having a few problems compiling a list box that is conditional on what is selected in another list box. What i need is a List box (lstArea) that displays one thing when the List...
7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
28
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
3
by: Kumar | last post by:
Hi Folks, I have a question regarding conditional hyperlink in datagrid. I want to display Hyperlink if my QID values in (1,4,5,6) other wise i want to display just Qdescription with out...
3
by: Paul Say | last post by:
I have a asp.net application that will need to create a document/report from data in a database. The user will fill out a form supplying various criteria for parameters. I would like the...
5
by: Gary Wessle | last post by:
Hi I have a group of functions which have the same signature. void fun_n(void); according to a conditional structure "be it if-else or switch-case" I get to choose which one to run. ...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
3
by: ezmeralda | last post by:
Hello, I have some code which shall be compiled in .NET v1.1 and v2.0 but which has to be different for the two .NET-Versions. Therefore I need to use a construct like #if NET_20 <2.0...
4
by: ApexData | last post by:
In a Continuous form, I want to use Conditional Formatting to change the background color of a date field based on a condition. 1-The color chart in the CF menu option offers limited colors. How...
10
by: VK | last post by:
Taking into account many new features in JavaScript1.6 and JavaScript1.7 which are syntactically incompatible with Javascript versions run on other browsers: would it be reasonable to propose as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.