jquery address in combination with "regular" anchor points - anchor

On this site we've implemented Jquery Address to remember and load ajax content correctly
when using back/forward buttons in the browser.
The problem have arisen with links that has regular anchor points, that is:
<a href="product.php?prodid=5" name="product5" />a product link</a>
the purpose of this is of course to make brwoser scroll down to same position
you were before clicking the link and clicking back (this is a product listing page for the record).
Is there a way to exclude (or not include) certain links that jquery adress catches?

You could just exclude all of the links with a name attribute:
// Use this selector when initializing jQuery Address.
$('a:not([name])').address()

Related

jquery mobile changePage not working if called from an ajax loaded page

situation:
form1.html has a button
clicking that button calls $.mobile.changePage('../site3/form2.html');
no problem here. all is as expected and the page is loaded. let's call that form2.html
form2.html has 2 sections:
(1) #SiteForm and
(2) #SiteSearched
clicking a button on #SiteForm should call $.mobile.changePage('../site3/form2.html#SiteSearched');
now here's the weird part.
if I load the page form2.html directly and press the button, it works and I see #SiteSearched JQM page.
but, if I start from form1.html, click the button to get to form2.html#SiteForm, then click the button, everything in the attached function executes, except the line calling $.mobile.changePage('../site3/form2.html#SiteSearched');
I know that part is loaded by AJAX by wouldn't the changePage command work?
(note: Form1 may have data filled into the form that I don't want to lose. Form2.html was meant to do a search and throw back the result to Form1 somehow, which is why I am doing things this way.)
You should read official jQuery Mobile documentation before posting here, everything is explained there, but let me give you a short explanation.
jQuery Mobile has two template solutions, one is multi page and second one is multi html. You already know that because you are mixing them. But, what you don't know is (from the perspective of AJAX page handling):
Only first HTML page is fully loaded into the DOM, everything is loaded, including the HEAD content. So if initial HTML page has several data-role="page" <div> containers, every one will load into the DOM.
But, every subsequent page is loaded only partially. Basically if you second, third ... page has more then one data-role="page" div containers only first one will load into the <DOM>. jQuery Mobile will discard everything else.
So in your case, if form2.html has:
(1) #SiteForm and
(2) #SiteSearched
jQuery Mobile will load only #SiteForm, #SiteSearched will get discarded.
Basically this line will not work:
$.mobile.changePage('../site3/form2.html#SiteSearched');
You can't nit pick specific pages in subsequent pages, as I told you. You can only use this:
$.mobile.changePage('../site3/form2.html');
And jQuery Mobile will show you first data-role="page" occurrence inside form2.html page.
Read more about this here and here.

How to ensure that all the non-origin href links open in a new tab?

I have a html content stored in backend, which may have certain anchor tags with href links, when rendering them I build a custom NodeValidator and then bind the value using a angular.dart decorator. Some of the href links points to outside my domain, I want to make sure that target='_blank' is added as attribute to such anchor tags so that browsers open the link in a new tab. Can this be taken care of by some UriPolicy or custom NodeValidator?

Link without jumping to top of page

I have the following link on my website:
<a href="/pages/getting-started-step-2-of-5" title="Next Step">
<span style="text-decoration: underline;">Next Step</span>
</a>
It works fine, however, would it be possible to change it so that when the link is clicked and the new page is opened it does not automatically scroll to the top of the page? i.e. the new page is in the same position as the previous page was?
Yes, if you read about Internal links.
Yes it is possible using HTML tags.
You should be using anchors.
You can have named anchors to jump to.
<a name ="jumphere">here</a>
You can jump to named anchors by using there names after a #.
http://somedns.com/index.php#jumphere
more info
Named anchors are no longer supported in HTML5 - use id instead in HTML5 pages.

jQuery mobile force full reload when link clicked

I have a "normal" link in my jqm page like this:
<a href="http://www.mysite.com/mobile/page.php?attribute=value">
And if I click it it won't properly refresh taking into account the attribute value and loading everything that's needed for it dynamically based on the attribute value. I understand that this is due to the fact that jqm tries to do an ajax call like mentioned here:
When you use pageChange an Ajax request will be made to that url and it will be
loaded only the content inside the div with data-role="page". So everything you
have out of this element will be ignored (JS and CSS).
So, I found out in the docs that I should use $.mobile.ajaxEnabled=false; or rel=external on links or target=_blank on the link.
Strange thing though for me is that only when I set the target=_blank property to my links will this truly happen. So, am wondering if someone had this kind of a problem and how did you solve it? The thing is, I would like to refrain myself form using target=_blank as it opens a new tab in my browser (as expected, but this is not nice from users' POV).
jqm version I use is 1.2
This question now at the top of google search results, so figured I'd answer:
Use the data-ajax attribute and set it to false to force reload upon clicking a link:
data-ajax="false"
use it like:
<a href="/" data-ajax="false">
<img id="mainLogo" src="logo.svg" width="215" />
</a>
And then your link will force reload the page!
Linking without Ajax
Links that point to other domains or that have rel="external",
data-ajax="false" or target attributes will not be loaded with Ajax.
Instead, these links will cause a full page refresh with no animated
transition. Both attributes (rel="external" and data-ajax="false")
have the same effect, but a different semantic meaning: rel="external"
should be used when linking to another site or domain, while
data-ajax="false" is useful for simply opting a page within your
domain from being loaded via Ajax. Because of security restrictions,
the framework always opts links to external domains out of the Ajax
behavior.
Parts taken from https://stackoverflow.com/a/22951472
Make function for the onclick event of the link.See the below code example.Hope this helps!
<script type="text/javascript">
function loadPage(url){
document.location.href = url;
}
<script/>
<a href="#" onClick="loadPage('http://www.mysite.com/mobile/page.php?attribute=value');">

load all "jquery mobile pages" within a html document fetched via ajax

Please let me know how to load all the "pages" in a html document into the current page dom.
I tried using $.mobile.loadPage, but only the first "page" of the document is loaded.
I want to load all the "pages" in that html document.
While googling for this i found two plugins ToddThomson/jQuery-Mobile-Subpage-Widget and a multiview plugin. But i could not find the basic "how to use" section for these two plugins.
Is there any links which shows how to use these plugins.
It can be done easily.
Lets say you have 2 html files. First one has a one jQM page and second html has two pages. Also lets say first html page is called test1.html and second one is called test2.html, test1.html is first page to open.
Only thing you need to do (to load every page from test2.html) is to add an attribute data-prefetch to a a tag link leading to the second page.
Here's an example:
<a href="test2.html" class="ui-btn-right" data-prefetch>Next</a>
If you wish, go to my profile and send me an email, and I will send you a working example.
Here you can find more about data prefetch in jQM: http://jquerymobile.com/test/docs/pages/page-cache.html
If you are changing your page with a changePage function you can still prefetch it with a :
pageContainerElement.page({ domCache: true });

Resources