[removed] not working correctly in IE7/8

后端 未结 4 1266
天命终不由人
天命终不由人 2020-12-21 05:16

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:

4条回答
  •  旧时难觅i
    2020-12-21 05:36

    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.

提交回复
热议问题