简体   繁体   中英

ie vs chrome window.location.href and <base> tag

I have a problem with redirecting with javascript to a different page upon the click on a <td> . For my websites I use the <base href=""> tag as a starting point for my links.

So consider this code:

<!doctype html>
<html lang="en"><head>
    <meta charset="utf-8"/>
<title>Login</title>
<base href="http://www.mysite.com/MyWebsite/manage/" />

special reference to <base href="http://www.mysite.com/MyWebsite/manage/" />

and consider this jQuery:

//Set row clicking
    $('table#alerts_table').on("click", "td", function () {
        var alert_id = $(this).closest('tr').find('input[type=checkbox]').val();
        var href = 'alerts/alert.php?id=' + alert_id;
        if (href) { window.location.href = href; }
    });

special reference to

var href = 'alerts/alert.php?id=' + alert_id;
if (href) { window.location.href = href; }

and consider that my current position on the website is already in the folder called alerts as follows: http://www.mysite.com/MyWebsite/manage/ alerts /index.php

I want to move from index.php to alert.php.

On chrome all works as expected ie the base href http://www.mysite.com/MyWebsite/manage/ is concatenated to alerts/alert.php?id=1 and I am redirected accordingly.

However in IE the folder alerts is doubled: http://www.mysite.com/MyWebsite/manage/ alerts/alerts /alert.php?id=1

This means that it is not taking the base URL from the base tag but it is using relative paths.

Any ideas?

you may use:

   document.location.replace(); 

function. you will not reqire to use the base option. it will be redirected to page or subdirectory present in the same directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM