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

Problems with location.href, query URL and IE(Mac) & Safari

Sorry if this is a rookie mistake... I've been through all the FAQs and the
books I have but I can't see the mistake so I guess it's something simple
<g> - I'm an occasional JS user.

I've got some code (in an external JS file) attached to a number of links
off a query result page. The code it checks if there are any ticked items on
the page and adds them to a lightbox (cart) before going the next called
result page. The idea is to stop the user taking any link off the page and
inadvertently remembering to add their selections to the lightbox.

The initial call is from a link, either to another result page in the same
query 'set' or to various static pages or predefined queries. The example
below is a call to load the lightbox (code my wrap):
<a href="#"
onclick="goWhere('LIGHTBOX','../scripts/portweb.dll?show&catalog=test&templa
te=lightbox','ADD',document.resultAdd);">Show Lightbox</a>

function goWhere(linkName,theURL,task,theForm) takes parameters for the type
of destination, the query string, the action (Add or Delete) for the
lightbox and the calling form. If there are no checked items (for adding to
the lightbox) on the page, the call falls through the various functions
passing back 'theURL' which is than set as the page is called as (code
excerpt):

var target = constructURL(linkName, theURL);
document.location.href = target;

Note - the query strings being used are otherwise fine and not, I believe,
the cause of the problem.

So, the code executes in a function in an external file. It words fine in
IE6 Win but in IE5 Mac and Safari 1 Mac it stops. It seems the location.href
is not being executed correctly and this is where the code breaks. It even
breaks if, as a test, I use
document.location.href = 'index.htm';
to point to a static page. The Mac browsers just don't seem to like
location.href.

Any pointers gratefully received,

Regards

Mark
Jul 20 '05 #1
4 8796
"Mark Anderson" <ma**@notmeyeardley.demon.co.uk> writes:
<a href="#"
onclick="goWhere('LIGHTBOX','../scripts/portweb.dll?show&catalog=test&templa
te=lightbox','ADD',document.resultAdd);">Show Lightbox</a>
Remember to return false form your onclick handler. Some browsers will
reload the page otherwise.

You should escape your "&"'s in attributes, by turning them into
"&amp;".
(code excerpt):

var target = constructURL(linkName, theURL);
document.location.href = target;


Try
location.href = target;
The location object is usually a property of the window, not the
document.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse,

Thanks. both fixes were right on the money.

The use of return false with onClick calls in the older/more picky browsers
is one of the least well documented. Oddly it is one think the otherwise
good O'Reilly JS books don't bother to cover.

If there are any well explained (i.e. little assumed knowledge) examples of
correct use of 'return false' within <a> link events, I'd be very happy if
you or anyone else could note the URLs

Regards

Mark
Jul 20 '05 #3
"Mark Anderson" <ma**@notmeyeardley.demon.co.uk> writes:
If there are any well explained (i.e. little assumed knowledge) examples of
correct use of 'return false' within <a> link events, I'd be very happy if
you or anyone else could note the URLs


I don't have an URL available, but the rule is simple:

If you don't return false, the link is followed (as if there was no
onclick handler). If you do return false, the click event is canceled,
and the link is not followed.

You should always return false if you don't mean to follow the link.

What you ran into here was a combination of this and the href="#" link.
It points to the current page, at a non-existing identifier (just as
href="#foo" would point to the element with id="foo"). Since it is the
current page, the browser don't *need* to load it, but some do anyway
(which could probably be correct for dynamic pages). Internet Explorer
doesn't change anything when following href="#", which is why you
could get away with not returning the appropriate false.

Generally, all events are cancelled by returning false from the
handler (if the event can be canceled at all, obviously).

The more modern way of attaching event handlers to elements is the W3C
DOM 2. There, you don't return false. Instead you call the method
preventDefault on the event object. All browsers still support the old
way, and probably will for quite a while, and IE doesn't understand
W3C DOM 2 Events at all.

Returning false is mentioned in some of the FAQ entries:
<URL:http://jibbering.com/faq/#FAQ4_24>
<URL:http://jibbering.com/faq/#FAQ4_27>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Lasse,

Thanks. My problem in solving the last was in large part through wrongly
diagnosing the location.href call as the cause.

Regards

Mark
Jul 20 '05 #5

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

Similar topics

2
by: Steve Lockridge | last post by:
We have recently created simple javascript rollovers on a site using Macromedia Fireworks. What is weird is that four of them work and one doesn't on the Mac platform using Safari and IE. The NN...
0
by: Ryan | last post by:
I have a site at http://www.chancesend.com/news.html which displays fine in all PC browsers, but does an odd thing in IE for the Mac. In the div#main section, I have the main #content div...
5
by: Frostillicus | last post by:
I've created a page that will contain a the thumbnails of photos I took in Beijing a couple of years back but since making each thumbnail <div> a float: left the <h1> tag in the document...
2
by: Ian Beer | last post by:
I am told by a couple of Mac users that a site I am building does not display properly under either IE or Safari, they no not seem to agree however exactly what the display problems are. CSS (&...
3
by: Odo | last post by:
Hi, my Problem is that I want to use an empty div with 20pix height as a seperator. With Firefox and Safari everything is fine. But IE/Mac do not display the height, instead there is only a...
1
by: Niladri | last post by:
Hi All, I have developed a ASP.NET application for online design of cards. It works fine on IE 5 above in windows, however i have heard from my client that, it is not running in IE Mac. Since i...
5
by: Bob | last post by:
Hi All: I'm trying to build an Ajax component that needs to support IE/Mac. Does anybody know if it supports XMLHTTP? It appears to have ActiveXObject, but I can't seem to get it to instantiate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.