javascript - jQuery Link Navigation Function -
hi i've been trying work while.
basically we've rebuilt mobile/desktop version of our site. trying create quick jquery script make pages , links contain our url load using .load() jquery feature. don't want go on 97 pages, , 10 scripts. using...
<a href=<?php echo protocol."secure3.idsma.".url."/secure/user/authentication/sso/login/initiate?returnurl=$return"; ?>">
and trying script do.
<a onclick="$('html').load('<?php echo protocol."secure3.idsma.".url."/secure/user/authentication/sso/login/initiate?returnurl=$return"; ?>')">
but i'm trying make more effiecent making script can detect link our site , add class triggers jquery function load pages.
also when link clicked how .scrolltotop() jquery function work?
thanks help. sorry english sentence structure isn't great.
please if can. in advanced again help.
i'd think you'd have this
$(document).ready(function(){ // find links within document $('a').click(function(ev){ // handle click on internal link here, recognized existence of secure3.idsma string if($(this).attr('href').indexof('secure3.idsma') !== -1) { ev.preventdefault(); // load link via ajax $.ajax({ url: $(this).attr('href'), success: function(response){ // populate html, , use animate scroll top $("html").html(response).add('body').animate({ scrolltop: 0 }); } }); } }); });
however, i'd advise against using ajax way - generally, don't want reload entire document; want reload parts of document changing, so, div#main-container
, etc. bear in mind you'll have apply function on content you've inserted (so script should in bootstrap)
Comments
Post a Comment