문제

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;
});

다른 팁

If you can use jquery or jquery mobile, use this to replace all links

$(function() {
    $("a").each(function() { 
        $(this).attr("href", "javascript:intel...('" + $(this).attr("href") +"')"); 
    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top