1

I'm using a free weather forecast widget in my website.

<script type="text/javascript" src="http://tools.tititudorancea.com/weather_forecast.js?place=zurich_2&amp;s=1&amp;days=5&amp;utf8=no&amp;columns=5&amp;temp=c"></script>
<div style="font: 10px Arial, sans-serif; color: #000000" align="right">
<a href="http://www.tititudorancea.com/z/weather.htm">Weather forecast</a> provided by <a href="http://www.tititudorancea.com/">tititudorancea.com</a></div>

My webpage will never reload itself and then the weather will never be updated. Is there a way to refresh the javascript without refreshing the all page?

Thanks in advance

3 Answers 3

2

You can just add a bogus query var at the end of the url to force a refresh. Add an id to your script tag first then try this:

var weather = document.getElementById('weather');

weather.src += '&bogus='+ new Date(); // init

setInterval(function() {
  weather.src = weather.src.replace(/&.+$/, '&bogus='+ new Date());
}, 1000);
Sign up to request clarification or add additional context in comments.

1 Comment

I tried your solution, but sadly it didn't work, the weather is not updating it self. Any Idea?
0

Here is the solution I found.

var weatherURLSite = "http://tools.tititudorancea.com/weather_forecast.js?place=$placeID$&s=1&days=5&utf8=no&columns=5&temp=c";    
var specificWeather = weatherURLSite.replace("$placeID$", value);   
$.ajax({
            type: "POST",
            async: false,
            url: weatherURL,
            data: { url: specificWeather }
        }).done(
            function (content) {
                var li = "<li id='" + value + "'>" + content + creditsDiv + "</li>";
                $("#weather").append(li);                   
            });

And I added a timer to do the refresh periodically

var weatherTimer = self.setInterval(function () { GetReloadWeather('@Url.Action("GetWeather","Weather")'); }, 3600000);

Comments

0

In my project I ended up with jQuery 'replaceWith' function

jQuery("script").eq(2).replaceWith('<script type="text/javascript" src="/state.js"></script>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.