How to load HTML file when using the windows timeout function? - javascript

So I'm trying to load my homepage HTML file after it a certain time frame. This is what I have right now:
reply.file('./views/afteradd.html');
setTimeout( function(){
window.location.href= "views/add.html";
}, 1000);
I want to load my add.html file after certain period however when I try to create a path to the my file I get an error. I have tried window.location and tried *.href. I'm pretty new in Java Script so it might be a really simple error im not finding.
The error I'm getting is:
"Debug: internal, implementation, error
ReferenceError: window is not defined"

If your add.html is not present in root location then please give full path in href
For this please try below code :
<script>
setTimeout(function(){window.location.href='http://yourdomainname/views/add.html'},1000);
</script>
And for home page add only '/'
<script>
setTimeout(function(){window.location.href="/"},1000);
</script>

Hello try with this.
<script>
var change_path = function(){window.location.href="/"};
setTimeout(change_path ,1000);
</script>

Related

Adding onclick=”GoTo(‘URL’) to a WordPress post

I want to add JavaScript attribute “onclick” with “go to” function inside a “span” tag: onclick=”GoTo(‘URL’) to a post on WordPress website.
When I add this code to a post:
<span class="aff" onclick="GoTo('URL')" target="blank">text</span>
nothing happens when you click on the "text" and there is an error “Uncaught ReferenceError: GoTo is not defined at HTMLSpanElement.onclick” at the console.
Please, help to fix the issue.
Add this ->
<script type="text/javascript">
var GoTo=function(url){
window.location.replace(url);
}
</script>
Can you add the code for your Goto function hard to know what wrong without that?
Assume something like
function GoTo(url){
window.location = url;
}

Loading Twitch Player fails with Twitch not defined

I am geting an error Uncaught ReferenceError: Twitch is not defined when I am trying to run the html code below:
<div class="custom-box well" id="templateHolder">
<script src="https://player.twitch.tv/js/embed/v1.js"></script>
<div id="testDivId"></div>
<script type="text/javascript">
var options = {width:600,height:400,channel:"cookingForNoobs"};
var player = new Twitch.Player("testDivId", options);
player.setVolume(0.5);
</script>
</div>
When I run it in jsfiddle it works and does not complain about not finding Twitch . However, as part of my page it does. The page correctly loads except for this div. Also using <iframe src="http://player.twitch.tv/?channel=cookingfornoobs&muted=true" width="100%" height="800px"></iframe> will work. I am not sure if there is something blocking the call for loading the Twitch player.
Is there something I can check for to make sure its being handled correctly?
As a note it occurs in Chrome as well as Firefox and I am able to see player.twitch.tv js/embed v1.js file under the sources tab.
When new Twitch.Player is interpretted your library might still be loading.
Try wrapping the twitch initialization within "DOMContentLoaded" or in window.onload = function(){} if you are using jquery then within $(document).ready(){}

Link + on(pagecontainershow) fail

I have a simple app done with jQuery Mobile, in some point I have this:
Start!
which loads a new HTML with a lot of jquery mobile pages:
<div data-role="page">
I have defined, in my external JS file, an global variable:
var startTimeQuestion;
And this method, which is inside my HTML (test_es.html):
<script>
$(document).on('pagecontainershow', function() {
console.log("Storing time..");
startTimeQuestion = new Date().getTime();
});
</script>
The problem is that when I click on the button it loads correctly the file but it seems like it don't load the JS or the function or I don't know, because when I'm going to use my startTimeQuestion variable it says UNDEFINED and it don't show in the console the 'Storing time..'. If a reload the page, it works fine.
I have tried to do an '$.(document).ready()' function for the first time I load the page but still not working. It looks like test_es.html it isn't loading my custom.css and my test.js file until I reload completely the page. So I supposed that the error is in how I call my test_es.html, it isn't this:
Start!
the correct way to do it?
Thanks.
Thanks to the comment before I found the solution, it was as simple as put the 'data-ajax' attribute to false this way:
Start!

Anonymous Function Error: $ is not defined

Google Developer Tools is displaying the following error when my PHP page uses the content from a javascript file (my_scripts.js):
"Uncaught ReferenceError: $ is not defined scripts.js:1 (anonymous function)"
Content of my_scripts.js
$('a.button').click(function(){
window.location.href = "another_page.php";
});
The page and the script work as required. Clicking the element links to the requested page, but the error is there.
1) What causes the error?
2) Can it or should it be ignored?
1) It looks like your problem is that jQuery haven't been loaded.
Make sure you load jQuery before scripts.js.
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
2) Errors should never be ignored.
You need to load jquery libary BEFORE! Please download the jquery.min.js at http://www.jquery.com/download/
also, write like this:
$(doucment).ready(function(){
$('a.button').on('click',function(){
window.location.href = "another_page.php";
});
});
If you have already included jQuery on your file, and still its not working you should try,
jQuery(doucment).ready(function(){
jQuery('a.button').on('click',function(){
window.location.href = "another_page.php";
});
});
This is causing as there might be some conflicting js files.

Galleria theme occasionally not loading

I am using the Galleria slideshow on my site, but I've noticed an error that seems to happen very randomly. Most of the time the slideshow loads correctrly but once in a while I get this error:
Uncaught Error: Fatal error: Theme at javascript/themes/classic/galleria.classic.js
could not load, check theme path.
When I reload the page, it's all back to normal.
This is the code I'm using to load it:
<script>
// Load the classic theme
Galleria.loadTheme('javascript/themes/classic/galleria.classic.js');
</script>
I have searched around but still haven't found a solution that works. My personal idea was to have a script that keeps loading until it succeeds, since on reload the page works.
How would I do this?
1 Try the latest build at gihub: https://github.com/aino/galleria/blob/master/src/galleria.js
2 Try loading the theme using a script tag instead:
<script src="javascript/themes/classic/galleria.classic.js"></script>
I adopted the method pointed out by David, loading the theme using a script tag:
<script src="javascript/themes/classic/galleria.classic.js"></script>
But was eventually getting another error (Fatal error: Theme CSS could not load after 20 sec). I'd also recommend adding the CSS using a link tag:
<link rel="stylesheet" type="text/css" href="galleria/themes/classic/galleria.classic.css" />
I had a similar message today when I tried using Galleria. It happened only in Firefox. What I did to get around it is to add the theme stylesheet link directly in the head. I kept the theme script link in too, after the stylesheet, just in case it was needed. After that, the error message went away and Galleria is working as it should.
Judging from where the error message comes from, and considering the random occurrences, this issue could be from simply hitting the timeout when loading:
Galleria.loadTheme = function( src, options ) {
var loaded = false,
length = _galleries.length,
err = window.setTimeout( function() {
Galleria.raise( "Theme at " + src + " could not load, check theme path.", true );
}, 5000 );
In version 1.2.2, the timeout is just 2 seconds, in the above (1.2.6) the timeout is 5 seconds. So upgrading to the later version, or customizing the timeout is definitely something to try.
Given the random behavior, it feels like a browser bug. More specifically, that the browser looses track of the base URL. I would give the full path from the webroot and see if the error goes away. For example:
Galleria.loadTheme('/gallery/javascript/themes/classic/galleria.classic.js');
If this don't help, try:
try {
Galleria.loadTheme('javascript/themes/classic/galleria.classic.js');
}
catch(e) {
location.reload();
}
But this can go infinitely. I would try to get to the bottom of the error and start with different browsers to rule out a bug in your code.
The Beginners Guide states that the script tag in which you load the theme needs to be after the images in the html source. You have probably added the script tag in the head tag. Example from the guide:
<body>
<div id="galleria">
<img src="photo1.jpg">
<img src="photo2.jpg">
<img src="photo3.jpg">
</div>
<script>
Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
Galleria.run('#galleria');
</script>
</body>

Categories