473,382 Members | 1,147 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,382 software developers and data experts.

dynamic link depending upon the history of the window

hsriat
1,654 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. function loadLink() {
  2. document.getElementById('link').innerHTML = history.length>1 ? '<a class="button" href="#back" onclick="history.back();return false;">&nbsp;Go Back&nbsp;</a>' : '<a class="button" href="#close" onclick="window.close();return false;">&nbsp;Close window&nbsp;</a>';
  3. }
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?
May 4 '08 #1
5 1579
acoder
16,027 Expert Mod 8TB
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.
May 5 '08 #2
hsriat
1,654 Expert 1GB
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. :)
May 5 '08 #3
acoder
16,027 Expert Mod 8TB
Have you tried the cookie option? Set the cookie depending on whether the target is "_blank" or not.
May 5 '08 #4
hsriat
1,654 Expert 1GB
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. ;)
May 5 '08 #5
acoder
16,027 Expert Mod 8TB
Well, in that case, all is well and good.
May 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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. ...
1
by: FluxForums | last post by:
<a href="" onclick="history.go(-1); return false;">Your Image or Tex Link</a -- FluxForum ----------------------------------------------------------------------- FluxForums's Profile:...
2
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...
4
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...
36
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...
6
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,...
23
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) { ..... }
15
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...
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: 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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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.