Remove ajax call from regular links using jQuery Mobile

Using jQuery Mobile I would like to disable ajax call on links in a specific part of the DOM.

I do not want to bet

data-ajax = false 

every time I don't want to use jquerymobile ajax.

For example, any link that is a child of 'content':

 <div class="content"> <a href="http://externalwebsite.com">External Link</a> </div> 

I would like to add 'data-ajax = false' to every link that is a child of 'content'

Is there any way to do this using jquery?

+7
source share
3 answers

If you want to disable the behavior of the ajax link from the anchor tag, you can put rel=external in the link and the link will load without ajax, and then your URL will be normal.

http://jquerymobile.com/demos/1.0a4.1/#docs/pages/docs-navmodel.html

 <a href="User/somepage" rel="external" />I wont be using ajax for navigation</a> 

If you want to do this in jQuery for some tags inside div content, you can try like this:

 $(function(){ $(".content a").each(function(){ $(this).attr("rel","external"); }); }); 

Here is an example http://jsfiddle.net/4WEBk/3/

More simplified version. (Thanks to tandu for pointing)

 $(function(){ $(".content a").attr("rel","external"); }); 
+18
source
 $(".content a").attr('data-ajax', false); 
+5
source

I had to add rel = "external" and target = "_ self" to make it work.

Under certain conditions, regular HTTP requests will be used instead of Ajax requests. One case where this is true is when you link to pages from external websites. You can also specify that a normal HTTP request will be using the following link attributes:

  • rel = external

  • target (any value, for example "_blank")

0
source

All Articles