Reputation: 35
I have got a problem with a script on a website I am developing. It works fine in Safari, Opera and Chrome, but it doesn't work in firefox.
As you click a link, I try to load the div #contain from internal links to an overlay div, which then is unhidden. All this is working fine in the browsers I have mentioned above, but it wont work in firefox, the click function just opens the link (reloads the page) as it would normally do.
Any Ideas why it does not work in Firefox? Anything that I am missing?
$(document).ready(function(){
var $ov = $('.overlay'),
$tp = $('#transparent'),
URL = ' ',
siteURL = "http://" + top.location.host.toString(),
$internal = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']:not('.no')"),
hash = window.location.hash,
$el, $allLinks = $("a");
$tp.hide();
$ov.hide();
$tp.click(function(){
$ov.empty();
$tp.hide();
$ov.hide();
});
if (hash) {
$ov.show();
$tp.show();
hash = hash.substring(1);
URL = hash + " #contain";
$ov.load(URL);
};
$internal.each(function(){
$(this).attr("href", "#" + this.pathname);
}).click(function(){
$tp.show();
$ov.show();
$el = $(this);
URL = $el.attr("href").substring(1);
URL = URL + " #contain",
$ov.load(URL);
});
});
Upvotes: 0
Views: 2817
Reputation: 11
Try to change the default behaviour of the browser :
(event.preventDefault) ? event.preventDefault() : event.returnValue = false;
Upvotes: 0
Reputation: 926
I think you are missing preventDefault in your click function. This tells jQuery/javascript to not follow the default action which in your case would be following wherever the link is pointing to in HREF.
Instead of
$tp.click(function(){
$ov.empty();
$tp.hide();
$ov.hide();
});
It should be
$tp.click(function(e){
e.preventDefault;
$ov.empty();
$tp.hide();
$ov.hide();
});
Upvotes: 1
Reputation: 3926
instead of
$tp.click(function(
try
$(document).on('click','#transparent',function(event){
//do whatever you want to do
});
Upvotes: 0