脚本里面的href how to
Script inside href how to
我正在使用这个链接:
<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);
相关文章:
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- how to convert html <div> to pdf
- how to split a string with ','
- How to declare a Map containing certain properties with flow
- How to apply javascript on <asp:Buttonfield>?
- How to target an h1 inside an <a>?
- How to “emitter.setMaxListeners()”?
- How to replace space with " "
- vue-router:how to not `saveScrollPosition`
- jquery ajax post to .aspx page load - how to read variable p
- 用Angularjs返回两个承诺,How To Chain So UI有$scope
- How to do "HTML FORM action=location.replace('nextp
- How to center tempAlert by Travis J
- How to POST javascript Blob to JAX-WS Web service
- jquery ajax how to trat callback
- How to tell javascript x.value = $('#selectID option:
- WinJS listview iteminvokedHanlder how to
- C# WPF WebBroswer Control: How to use JavaScript
- how to make a <div> appear in slow motion
- JS, how to stop process execution if it's beeing execute