Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript创建链接_Javascript - Fatal编程技术网

使用javascript创建链接

使用javascript创建链接,javascript,Javascript,我试图在JS中创建一个链接,将这个人移动到他来自的页面。这是代码 <script language="javascript"> function Jump() { document.href=document.referrer; } </script> 函数跳转() { document.href=document.referer; } 这是html <a href="#" onclick="Jump();">Skip and Continue<

我试图在JS中创建一个链接,将这个人移动到他来自的页面。这是代码

<script  language="javascript">
function Jump()
{
document.href=document.referrer;
}
</script>

函数跳转()
{
document.href=document.referer;
}
这是html

<a href="#" onclick="Jump();">Skip and Continue</a>


现在,当用户单击链接时,什么也没有发生。请告诉我哪里做错了。谢谢

使用下面的代码向后移动怎么样

 history.back();

出于隐私原因,许多浏览器不会使用
document.referer
,尤其是如果该referer来自其他域


相反,请尝试使用
onclick=“history.go(-1)”
而不是
Jump()
函数。

绑定单击侦听器比使用
onclick
更好

尝试将其更改为:

<a id="myLink" href="#">Skip and Continue</a>

和Javascript:

<script type="text/javascript">
document.getElementById('myLink').addEventListener('click', function(e) {
    e.preventDefault();
    document.location.href=document.referrer; //actually better as "history.back()"
}
</script>

document.getElementById('myLink')。addEventListener('click',函数(e){
e、 预防默认值();
document.location.href=document.referer;//实际上最好是“history.back()”
}

它不是document.href,而是window.location.href

<script>
function Jump(){
    if(document.referrer)location.href=document.referrer;
    else history.back();
}
</script>

函数跳转(){
if(document.referer)location.href=document.referer;
else-history.back();
}

(如果您使用跳转进入当前页面,则没有推荐人。)

尝试以下操作:document.location.href=document.referer;可能您的推荐人是empty@terabaud:像一个符咒一样工作。
document.href
不是什么东西。@sachlen哦,糟糕,复制/粘贴。编辑。添加此代码以查看您使用的broswer是否支持推荐人。如果('referer'在文档中){console.log(document.referer);}