脚本里面的href how to

Script inside href how to

本文关键字:how to href 脚本      更新时间:2023-09-26

我正在使用这个链接:

<a href="javascript:location='http://www.linkimprov.com/?ref='+encodeURI(location.href).substring(7);"></a>

用作书签。当点击它时,它将用户重定向到一个url,该url采用前一个位置,删除其中的前7个字符。

不是从'+encodeURI(location.href)'中删除前7个字符,我希望它这样做:

if(encodeURI(location.href).match(/http:'/'//))
{
encodeURI(location.href).substring(7);
}    
if(encodeURI(location.href).match(/https:'/'//))
{
encodeURI(location.href).substring(8);
}
if(encodeURI(location.href).match(/^www'./))
{
encodeURI(location.href).substring(4);
}

如何使它在href中工作?

谢谢

这样如何:

location = 'http://www.linkimprov.com/?ref=' + encodeURI(
    location.href.match(/(?=https?:'/'/)?(?=www'.)?(.*)/)[1]
).substring(7);

或者在链接中:

<a href="javascript:location='http://www.linkimprov.com/?ref='+encodeURI(location.href.match(/(?=https?:'/'/)?(?=www'.)?(.*)/)[1]).substring(7);"></a>

编辑:试试这个:

 location = 'http://www.linkimprov.com/?ref=' + encodeURI(
    location.href.match(/^(https?:'/'/)?(www'.)?(.*)/).pop()
).substring(7);