开发者

Jquery/Jquery mobile - how to detect if a link clicked leads to an image or website?

开发者 https://www.devze.com 2023-04-06 09:22 出处:网络
I\'m trying to combine two JQM plugins and am stuck clearing out conflicts. I have the following, which when clicked activates the Photoswipe plugin:

I'm trying to combine two JQM plugins and am stuck clearing out conflicts.

I have the following, which when clicked activates the Photoswipe plugin:

<a class="swipeMe" href="../IMG/samples/166.png" rel="external"><img src="...

In the 2nd splitview plugin a clicked link with rel="external" fires the JQM HttpCleanup function:

httpCleanup = function(){
    window.setTimeout( function() { removeActiveLinkClass( true ); }, 200 );
    };

which gives me an "removeActiveLinkClass is not defined" error. The other error I'm getting is on closing Photoswipe, where firebug tells me "$.mobile._handleHashChange is not a function"

So I assume I need to add an if-clause that says: "if the link clicked is an image/not a webpage, skip the HTTPCleanup and don't do a hashChange".

How can I do this in Jquery or JqueryMobile?

EDIT: more code..

I think these are the relevant poritions of code

$(document).bind( "click", function(event) {

httpCleanup = function(){
    window.setTimeout( funct开发者_运维百科ion() { removeActiveLinkClass( true ); }, 200 );
    };      

    var isExternal = useDefaultUrlHandling || ( $.mobile.path.isExternal( href ) && !isCrossDomainPageLoad );

    if( isExternal ) {           
   httpCleanup();
   //use default click handling
   return;
       }


Try this:

$.ajax({
   type: 'GET',
   url: $("a.swipeMe").attr("href"),
   complete: function(resp){
        ct = resp.getResponseHeader('Content-Type');
        }
   });

If ct=="image/png", you have a PNG image.


you could just add a class to the anchor tags, when rendering them, and verify if it has that css class on it, in your cleanup function

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号