重新命名或替换HTML文件中的所有网址 [英] rename or replace all urls in html file per javascript
问题描述
我有一个jquerymobile web应用程序,并希望保留html文件中所有现有数百个不同的外部url链接,如
< a href =http://www.example.comtarget =_ blankdata-rel =external>连结< / a>
但想让它们表现如下:
< a href =javascript:intel.xdk.device.launchExternal('http://www.example.com');>
我会怎么做(没有搜索并替换)脚本?
非常感谢您的帮助。
我想为所有链接添加一个事件处理程序,比如这:
$(document).on('click','a',function(){
this .href =javascript:intel.xdk.device.launchExternal('+ this.href +');;
});
只有在点击链接时才能完成作业。
或者,感谢 bencol :
<$ ($'code> $(document).on('click','a',function(){
javascript:intel.xdk.device.launchExternal(this.href);
返回false;
});
I have a jquerymobile web app and want to keep all existing hundreds of different external url links in the html file like
<a href="http://www.example.com" target="_blank" data-rel="external">Link</a>
but want to make them behave like this:
<a href="javascript:intel.xdk.device.launchExternal('http://www.example.com');">
How would I do that (without search and replace) with a script? Thanks a lot for your help.
I suppose you want to add an event handler for all links, like this:
$(document).on('click', 'a', function() {
this.href = "javascript:intel.xdk.device.launchExternal('" + this.href + "');";
});
The job will be done only when the link is clicked.
Or, thanks to bencol:
$(document).on('click', 'a', function() {
javascript:intel.xdk.device.launchExternal(this.href);
return false;
});
这篇关于重新命名或替换HTML文件中的所有网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!