简体   繁体   English

“javascript://”是什么意思?

[英]What does “javascript://” mean?

Recently I came across something like this 最近我遇到过这样的事情

<a href="javascript://">some link</a>

I have no clue what "javascript://" means in that code. 我不知道“javascript://”在该代码中是什么意思。 Does it mean a protocol named "javascript"? 这是否意味着一个名为“javascript”的协议?

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Further looking into it, javascript:// is not a valid protocol. 进一步研究, javascript://不是有效的协议。

Typically when you want to execute js via a link, you use javascript:doSomething(); 通常,当您想通过链接执行js时,可以使用javascript:doSomething(); .

In this case, 在这种情况下,

  • Let javascript: mean " execute Javascript code after the : " javascript:表示“ 执行后面的Javascript代码 :
  • And let // mean a Javascript comment. //表示Javascript评论。

It seems to be a placeholder to do nothing, just as javascript:; 它似乎是一个什么都不做的占位符,就像javascript:; would do. 会做。

So literally: execute // (do nothing) 字面意思是:执行// (什么都不做)

it leads to nowhere as no url is specified. 因为没有指定url,所以无处可去。

There are some other approach to the same thing: 还有一些其他方法可以做同样的事情:

href="#" adds an extra entry to the browser history (which is annoying when eg back-buttoning). href="#"在浏览器历史记录中添加了一个额外的条目(例如在回扣时很烦人)。

href="" reloads the page href=""重新加载页面

href="javascript:;" does not seem to have any problems (other than looking messy and meaningless) 似乎没有任何问题(除了看起来凌乱和毫无意义)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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