Recall external JS files after page transition finish - javascript

I have tried to implement this kind of script (Page Transition): here
Everything is going fine as demo provided. But only 1 problem that I cant figure out is:
I have 2 HTML files which is index.html & index2.html. On index.html I put the link with the page transition effect after clicked it goes to index2.html which is on index2.html I was put in some alert script using body on-load method.
Supposedly in normal practice, the alert will appear as normal we seen for debuging. But it doesn't appear anything. Seem like it doesn't load any script after page transition done.
Can somebody give me a clue to solve this? What I have tried is using :
location.reload(); window.location.reload(); etc.. till I don't have idea to fix this :(
*location.reload() works on desktop browser but doesn't work on mobile. My priority target browser is on mobile version.
Please help & Many Thanks
for demo purpose and needs help : here

It wasn't executed because the page never really loaded. The way that page transition script worked is by loading the content of the target page via ajax, replacing the entire content of the page with it.
From the page you provided, it seems like the script accepts a callback function to be called when the page finishes loading, you can put your 'loaded' script there. But keep in mind, what is being executed is the script on that first page.
I don't know what you are trying to make, but I guess it would be better for you to look into a proper single page app with URL matching. There are frameworks like Backbone.js that can help you with this.

Related

jQuery loses ability to read HTML and CSS tags inside AJAX script after location hash change

I'm experiencing some issues regarding an AJAX script I'm working on.
The page loads perfectly well, and all needed scripts are loaded the same for basic page functionality inside AJAX script, but after hash change, jQuery behaves awkwardly.
Let's take this example.
The custom jQuery script writes an inline CSS propriety for a specific DIV at page loading:
Now, I load the login page for example:
I get back to the main page and inline style disappears as well as the basic loaded functionalities cease to exist after Ajax call:
*
Any experience on this? Does anyone have a clue why this happens? Or even near it... Seems the script unloads on page/hash change, which I don't believe. Or enters in double loop, therefore doubling the classes for HTML. I don't get it.
Already searched a lot and went trough the coding and is fine becasue it works fine alongside with basic HTML. Would appreciate some thoughts on this matter.
Thanks!

Javascript linking to other pages

We're running over a problem here. We have a website which shows a header, content and a footer. Now, when clicking on a link we want just a part of the site (content-part) to be refreshed to save some traffic. The header and footer should stay as they're. We tried to use the following script for that:
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
Well, the script is not doing great on our site. Any other JS-Code does not get executed at all. The GET-Tags in the URL are not displayed aswell. Everything else works with that script.
Do you have knowledge about any other alternatives to this script?
Regards,
I agree, Ajax is the way.
You can include jQuery.
Have a look at these links.
http://api.jquery.com/jQuery.ajax/
In particular jquery load() function
$('#result').load('ajax/test.html');
a little jsFiddle
http://jsfiddle.net/james_nicholson/c6dpn/5/
please note: $("#content").load("a/html/page/that/should/be/on/your/server");
.load(); <- needs to have a local page, PHP and or HTML will do.
http://api.jquery.com/load/
When you say 'Any other JS-Code does not get executed at all', do you mean at any time from when the page loads initially, or only when the content part is refreshed?
For dynamic adjustment in javascript i would recommend http://angularjs.org/ or http://knockoutjs.com/ , try this out and work through tutorials and you will see how easy it is to change everything without refreshing.
I'd say you only need AJAX if you get some data from a database. Otherwise it's enough to work with AngularJS or KnockoutJS. Have a look at it!
Regards

jQuery+ AJAX + Help Hiding This Content

First of all: I hope the following question is not too generic.
I have a small problem and I cant think of a good solution and I was hoping some1 here is able to help me.
This is my situation:
I am using AJAX to dynamically load pages. My main site is index.php and once I click on a navigation link, the AJAX script replaces the content of index.php with new content and adds a hash tag to the URL. For instance:
I click on the link to about.php, the script adds #about.php to the URL and loads content from about.php into index.php. It works great :) However, there is a small issue that I would like to resolve:
Lets say we start by navigating to index.php#about.php directly - this means the content of index.php is visible for 2,3 seconds and than gets replaced with content from about.php. And I would like to avoid that.
I came up with a few ideas, but they are all not really great:
1) Hide content -> than make AJAX call -> on completed AJAX show content again
Downside: The content is still visible for a second.
2) Hide content with CSS and show it after AJAX call
Downside: This would work perfectly, but users without Javascript (and the GoogleBot) will see an exmpty page only.
3) Use an empty index.php and put the content of it in main.php and automatically load main.php via AJAX on page load.
Downside: Would work too, but again, users without JS and GoogleBot will just see an empty page when the visit index.php
Thats all I can think of and all three solutions are not good, because I am worried the SEO value will dramatically decrease when I have an empty index.php (I could accept that users with no JS get nothing to see).
p.s. I read somewhere that when you have display:none in an external css file and block it with robots.txt, GoogleBot wont know the difference, but I am worried thats maybe not the case? Any1 got some experience?
Edit: I guess my whole question comes down to this:
Do you think hiding the whole content of index.php with CSS (and than show it with JS), will be a huge no-go for SEO or will it be okay with GoogleBot (afterall the content is still in the source, but not visible to the user)?
If you used query strings instead of the hash you could have index.php load the correct content at the server level.
A plugin like history.js can help you push URLS to the browser so that you still get your ajax browsing.
Wow where to start...first of all the page 'blink' I'll call it is 2-3 seconds for you but it is completely dependent on the users computer, how fast it executes the javascript, and how fast the AJAX call returns so you could have a much larger delay.
Second I wouldn't worry about Googlebot seeing any of the ajax content. While it's true googlebot does try to fiddle with some javascript it won't make the ajax call like a normal browser would. I'd be very surprised if Googlebot ever saw any of your Ajax loaded data.
Googlebot does a fantastic job of figuring out what content is delivered via html/css to a user when they visit your page. It also figures out if something is displayed or not and does a good job of deciding if that content is just stuffing or is something that really matters.
You're worried about what someone without javascript will see when the entirety of navigating your site is based in javascript. This doesn't seem to reconcile.
You've got PHP available. My suggestion is to forgo the AJAX stuff you're trying to do and do it in PHP. You can just as easily script the same behavior in PHP as you can in AJAX.
SEO NOTES:
If you're looking for solid SEO results I suggest making the static (non-javascript version) page as SEO friendly as possible. I like to 'pick the low hanging fruit' like making sure the page has one and only on H1 and that it has the most important keywords in it. seomoz is one of the best sites I've found for seo information.

Firefox and IE6 issue with document.ready()

I have created an html page with a Tabber tab functionality.
Each tab has its own table that loads when the tab is clicked and only loads once on the initial tab click to stop the tables loading more than once.
Each tab table exists in its own .jsp html file and is loaded through javascript using the $("#tab1").load('tabqtable.jsp'); call.
I currently have a document.ready() within the individual tab html files to run when each tab loads. The scripts run and work perfectly in Chrome, but the document.ready() functions don't run in Firefox and IE6.
I can put an alert(); outside of the document.ready() function and it works, so I know the script tag is being run. I also tried moving all the javascript to the return function call in the .load() function so the javascript will run when the .load() runs successfully from the m/ain html page, but still ended up with the same result.
I am at a loss and would really appreciate some help on this issue if I could get it. The tables load perfectly, I just don't get any of the functionality I need in order to interact with the table. It's not the scripts I am running either, because they all work with the main html page. Thanks for any help in advance.
well it looks like you are already using a framework like jquery...use $(document).ready (assuming that's jquery you are using...) the point of frameworks like jquery is that it (in principle) should be crossbrowser compatible.

preventing JS running when the page is not loaded

I have encountered a problem. When I use jQuery to load a page that contains heavy javascript, the page freezes. I believe it is because the js executes before the page loads as my local site does not freeze. However, $(document).ready(function(){}); seems not working with dynamically loaded pages? is that true? or anything i could do to solve this problem. Thanks a million!
$(document).ready() works fine in dynamic pages. There must be an error in your code somewhere.
The first thing to do is to try View Source and save the HTML to a plain .html file, then load that file in your browser. If that still fails then you know the problem has nothing to do with the server-side ASP/PHP/whatever code. Then try removing HTML and JavaScript piece by piece until the problem disappears. That'll help you narrow down the culprit line(s). If you can reduce your page to a small file that still demonstrates the problem, post that here and we'll try to help.
Try using
$(window).load(function(){
dosomething();
});
It will run the js after the whole page is loaded.
Avoid using
$(document).ready(function(){
dosomething();
});
It will run the js just after the loading of DOM.

Categories

Resources