Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  35] [ 2]  / answers: 1 / hits: 21404  / 14 Years ago, thu, january 27, 2011, 12:00:00

I have a div which has an a inside it. I want to click on the div and follow the same url as the a. This is the HTML:



<div class=overview white getchildurl>
<p class=w70>
05-02-2011
</p>
<a class=button href=details/>Details</a>
<span class=clear></span>
</div>


and I have this script:



$('.getchildurl').each(function() {     
$(this).click(function() {
var href = $(this).children('a').first().attr('href');
window.location = href;
});
});


This works in Firefox 3.6, Chrome, Safari, but not in IE7 and IE8. It reloads the page, but stays on the same page. I checked the var href, it has the right url, but doesn't go there. What am I doing wrong?



Thanks.



EDIT: Making it an absolute URL made it work. This is the new script:



$('.getchildurl').each(function() {     
$(this).click(function() {
var href = $(this).children('a').first().attr('href');
var host = window.location.hostname;
window.location = 'http://' + host + '/' + href;
});
});

More From » jquery

 Answers
11

I am posting this as a different answer because it is a different answer. How to work through problem with JavaScript instead of work through it with HTML and CSS.



Try changing your JavaScript to display and make sure the values are what you think they are



$(this).click(function() {
var href = $(this).children('a').first().attr('href');
alert(href)
alert(href.length)
window.location = href;
});


That will display the href and the href length. Make sure the length matches up. If the length is too big then that means there are hidden characters.



If you determine that the problem is due to syntax, many URL fixes/conversions can be done with JavaScript. For example, removing a trailing slash when there is one can be done with



$(this).click(function() {
var href = $(this).children('a').first().attr('href');
window.location = href.replace(//$/, '');
});


Also, the URL could be converted to an absolute URL using JavaScript if that is what will fix the problem. And any other troublesome or even invisible characters can be either removed or replaced.



Can you post a web page on the internet that we can access to see the issue on our own copies of IE? Can you post an HTML file that we can copy to our machine and view in a browser? Your comment on the other question tells me you have some sort of XHTML strict DOCTYPE. If one of us can make the issue happen on our end, it is more likely to be fixed.


[#94023] Tuesday, January 25, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
julian

Total Points: 159
Total Questions: 105
Total Answers: 94

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;