hyperlink - New tab with preventDefault and jQuery load -
i have handler of hyperlinks preventdefault method there. want open link in new tab , load specific content jquery .load() method. best way this? here code of hyperlink handler , way load content.
$("a").click(function(event){ event.preventdefault(); if ($(this).attr("target")=="_blank"){ // open @ new tab , make actions } else { //some actions } }); $(".loadedcontent").click(function(){ $(".content").load("loadedcontent.html"); });
you can open link in new tab, remember not able access page using jquery. have load url have jquery .load() code. example:
if($(this).attr("target") == "_blank") { window.open('url'); } then in new tab, can load page you're having method. like:
<html> <body> <script> $(document).ready(function () { $('div').load('the_new_url.html'); }); // remember add jquery file html document. </script> <div></div> <!--you'll find new content in div--> </body> </html> it pretty messy!
to use .load() method using method on same page, load new content , replace existing content content being fetched. these popups annoy users! rex mentioned, answers opinion based, opinion use method on same page instead of new tab!
if me, have used above code populate content on dom load event. , on each element click, have updated content depending on element , event!
Comments
Post a Comment