I add a link on the onload event of the body.
The link is displayed as BACK if the page is opened from another page, but if the page is opened in a new window, its displayed as CLOSE
Here's the function. -
function loadLink() {
-
document.getElementById('link').innerHTML = history.length>1 ? '<a class="button" href="#back" onclick="history.back();return false;"> Go Back </a>' : '<a class="button" href="#close" onclick="window.close();return false;"> Close window </a>';
-
}
But the problem is.... history.length starts from 0 in Opera, Safari and IE, but starts from 1 in Firefox.
So how can I rewrite it without checking for which browser it is?
5 1579
You obviously can't depend on history.length, so you'll have to think of another way.
One possibility is to check document.referrer, but that depends on your application.
Another I can think of is to use cookies which you can set to determine history length.
If I use document.referrer, it would not work for the window if opened with a link with target="_blank" attribute. It would still return the referrer, while window doesn't have any history.
I'm trying to implement this in an error page. And that page can either be loaded in the same window, or a new window if corresponding link is targeted to _blank.
So if loaded in same window, it should show Back button, but if loaded in new window, it should show Close button.
So as for now, I would let the condition history.length>1 be there. As it covers both the conditions ie. history.length>1 & history.length>0. Just 1% would be exceptional case.
Thanks for your reply. :)
Have you tried the cookie option? Set the cookie depending on whether the target is "_blank" or not.
Have you tried the cookie option? Set the cookie depending on whether the target is "_blank" or not.
Actually this error page can be shown at any page if there's any trouble with the get parameters or the request wasn't valid or the user doesn't have right to view that page. And moreover its not a separate error page (something like show_error.php), but the requested page itself shows the error, without sending the redirecting headers.
So to implement cookies, I don't want to modify all the pages (Is that what you mean? or I'm not getting you?).
Moreover, the website is going to be used by few know people, and I've already recommended them to use Firefox :D. And by now all of them have started using Firefox and are happy with that. ;)
Well, in that case, all is well and good.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mr B |
last post by:
Howdy,
I want to set up an Include page in a cell of a table. Then I want to be able to change which page
is included on the fly as the user moves the mouse of the various links on the page. ...
|
by: FluxForums |
last post by:
<a href="" onclick="history.go(-1); return false;">Your Image or Tex
Link</a
--
FluxForum
-----------------------------------------------------------------------
FluxForums's Profile:...
|
by: Kevin Lyons |
last post by:
Hello,
Can anyone assist me with what I am trying to do with the following
code (six different scenarios to try to make the functionality work
correctly)?
I want to always (and ONLY) display...
|
by: Stromboli |
last post by:
hi people,
My problem is that I need to build a dynamic menu (preferably that
works in all the browsers) that appears when I mouseover a certain
link.
The problem is that I have to declare...
|
by: randau |
last post by:
I would like to use the Link Target attribute, but am
inhibited by the likelihood of a newly opened browser window
completely hiding the Parent browser window. Thus offering
the illusion that...
|
by: 35th Ave Media |
last post by:
Hello,
I have about 60+ pages that I need to insert a MAILTO: tag so people can
email the page using their email client. The body of the message is
going to be the URL of that page. Using ASP,...
|
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
|
by: firstcustomer |
last post by:
Further to my earlier post, I've found something that does partly what
I'm doing, but there are two issues:
1) There is an error in the script. Being a Javascript newbie, I've no
idea what the...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |