[英]Xpath with js and google chrome
I have a code for generating xpath on click but i need to put that in an chrome extension. 我有一个用于在单击时生成xpath的代码,但我需要将其放入chrome扩展程序中。 So how to do that? 那么该怎么做呢?
Here is the code for generating xpath on click: 这是单击生成xpath的代码:
function get_XPath(elt)
{var path = '';
for (; elt && elt.nodeType==1; elt=elt.parentNode)
{var idx=$(elt.parentNode).children(elt.tagName).index(elt)+1;
idx>1 ? (idx='['+idx+']') : (idx='');
path='/'+elt.tagName.toLowerCase()+idx+path;
}
return path;
}
$(document).ready(function() {
$('*').click(function(event) {
event.stopPropagation();
alert(get_XPath(this));
});
});
also you will see the demo here: http://jsfiddle.net/CksqX/ 您还将在此处看到该演示: http : //jsfiddle.net/CksqX/
How i can construct an chrome extension so when I click on some element on chrome current page to get xpath with my function in textfiled ? 我如何构造chrome扩展名,以便当我单击chrome当前页面上的某个元素以在textfiled中获取带有函数的xpath时?
How to pack this code to work as chrome extension? 如何打包此代码以用作chrome扩展程序?
Maybe the code is not very well but i will fix them, so i need to turn this into google chrome extension 也许代码不是很好,但是我会修复它们,所以我需要将其转换为google chrome扩展
sorry about trivial question,i'm new to web developing and sorry for my englsh 对琐碎的问题感到抱歉,我是网络开发的新手,对我的英语感到抱歉
您应该指定此https://developer.chrome.com/extensions/getstarted.html的具体部分-您可能不了解,这样我们才能定位您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.