简体   繁体   English

拾取网页链接

[英]Picking Up a link of a web page

I was just learning how to develop a link sharing system and came across a road block.I wanted to pick up the link of the current webpage opened in my browser. 我只是在学习如何开发链接共享系统,遇到了一个障碍。我想获取在浏览器中打开的当前网页的链接。 For eg if i am on "google.com" the it should pick up the link of it. 例如,如果我在“ google.com”上,则应该选择它的链接。 Also i wanted this link to be pasted in a input box that was designed by me so that i can notify the user as to on which page he is at the current moment. 我也希望将此链接粘贴到我设计的输入框中,以便我可以通知用户当前他在哪一页上。 I tried the OmniBox of Google to pick up the address but was not able to write a robust function for it in JavaScript. 我尝试使用Google的OmniBox提取地址,但无法在JavaScript中为其编写健壮的函数。

Just get it in your JS code, should be able to get the current url with: 只要在您的JS代码中获取它,就应该能够通过以下方式获取当前网址:

   var url = document.URL;
   var elem = document.getElementById("myinputbox");
   elem.value = url;

You could do the get/set in one line if you wanted to: 如果要执行以下操作,则可以在一行中进行获取/设置:

document.getElementById("myinputbox").value = url;

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

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