2

Im kind of new to javascript so please excuse me if this in a stupid question.

I have a website which shows a couple of graphs. The problem is that these graphs are drawn when the page is loaded which means that they keep their original size even if the width/height of the screen is changed. This has not been a problem on the desktop version but now I want to make it work on my iPhone and iPad aswell. This means that the graphs needs to be reloaded when I swap from portrait to landscape, and the other way around.

I have tried to solve this by adding a "onResize" to the body-tag. This works perfect when I resize my browser window in desktop mode and it also works fine on my iPhone. BUT the iPad gets caught in an infinite loop! WHY?

Please help me with this problem, I have spent faar to may hours on it now...

Here's the code I use:

In Header:

<script type="text/javascript">
function myfunction(){window.location.href = window.location.href;}
</script>    

And in body:

<body onresize="myfunction()">
  • 1
    maybe my brain is foggy, but why when the body is resized, do you assign the href of the window back to itself? Isn't this a no-op? – Matt Nov 27 '12 at 21:37
  • @Matt according to this it does perform an operation; at least in some cases: http://stackoverflow.com/questions/2405117/difference-between-window-location-href-window-location-href-and-window-location. However, I agree with you that it does look like a code smell; I guess it would be cleaner to decouple the data load from the page load and call the data load directly on resize. I don't know if that will solve the problem though, but I would expect it from the description above. – Maate Nov 27 '12 at 21:51
  • Thanks guys! function myfunction(){window.location.reload(true); } solved the issue of looping. For some reason, it also led to a new problem. The entire page is "zoomed in" to approximately 130% of the original size. WIERD. I guess it has nothing to do with the original question but this did not happen with the first way i tried, "window.location.href = window.location.href;". In the first version, there was no zoom effect and the page was resized in the right way, but it got stuck in the loop. Now the loop is gone but it gets zoomed in and thereby doesnt fit the screen. Any thoughts? – user1857826 Nov 28 '12 at 17:42
  • solved it, it was a bug in safari for mobile devices that was easy to solve. thanks for the help – user1857826 Nov 28 '12 at 18:01

0 Answers0