View Full Version : Example javascript for Opera please!!!

10-14-2003, 05:38 PM
Does anybody know of a site that provides working examples / code for javascript to make it work with Opera.

I am struggling to get all my javascript to work on Opera as it is all IE6 focused.

Should I just forget other browsers and focus soley on IE6? Who uses anything else except for developers.

10-14-2003, 08:03 PM
Opera does JavaScript quite well. What are you having problems with?

10-14-2003, 10:28 PM
Well firstly I can't get...


to work.

I understand that unlike all other browsers Opera takes the cache seriously and won't let me prevent it caching the pages! At least that is what I was told. But I can't get a workaround.

But my main point was, I come from an IE6 background and it seems to let me do javascript in a fairly relaxed way. When I try it out on Opera it always needs some fixing before it will work.

What I guess would be ideal is a site that shows how to achieve in opera the same result as you get from IE6.

In the old days everything was aimed at cross browser compatability with IE4 and Netscape (RIP), but now I guess Opera is the new competitor. So how to make things cross browser compatible for Opera and IE6??

You may say that I should learn to code javascript correctly - but as most of us learn from existing code (which works in IE6) - can you see it's a catch 22.

10-15-2003, 12:22 PM
Forward:  The "window.history.forward();" command works in Opera 6.05; what version are you using?

Caching:  Check out the "Samples of my work > Guaranteed Fresh" page at:


Catch 22:  Yes, copy code for learning purposes; no, don't use bad code on your pages.  Get a good book or web reference and learn to do it correctly.  I like:


10-15-2003, 01:31 PM
Opera 7 is the latest - if you're working with 6 then it's no surprise you're having difficulties - 7 was the first to have proper DOM support.

But window control is not part of the DOM ... and anything that involves manipulating the history is likely to be problematic - Opera is a lot more user-centric than IE, and it disallows a lot of things that would work in IE, for usability and security reasons. I don't know if this is one of those, but it might be.

10-15-2003, 02:08 PM
Opera 7.21 also does "window.history.forward();" correctly.

10-15-2003, 02:21 PM
Here is the code as it is on the page...

<script language='JavaScript'>

... I am using ....

Version 7.02
Build 2668
Platform Win32
System Windows XP
Java Java not installed

Can you please point out wher I am going wrong!

10-15-2003, 02:25 PM
<script language='JavaScript'>

This is not a function nor a link, it gets executed in-line as the page is loading.&nbsp; At that moment, there is no forward page to go to.&nbsp; Once you load another page and go back to this page, you could set off a link or function to go forward, and that should work properly.

10-15-2003, 02:30 PM
That's the point.

In IE6 when i load this page it does nothing (great), but when i go back to this page using the back button, it wont go back!

In opera the same page loads and does nothing (great too), but when i go back to it using the back button it shows the cached page.

10-15-2003, 02:38 PM
Maybe you want "window.location.replace('target.com');" instead.

10-15-2003, 02:46 PM
tried that too.

It seems the problem is a fundemental one where opera says that the cashe is a "photo" of what you saw earlier, whereas IE6 is happy to be played with by the programmer so that the cache is not what it seems.

If opera insists on caching strictly then the page it shows when you click the back button is not dynamic. things like onload() etc don't happen when you looked at cached files.

I tried using PHP server side to tell opera not to cache the page - this would force it to get the page from the web again and then all would work. But opera seems to ignore this too.

I think i must accept that opera's cache is not to be messed with. Resistance is futile!

10-15-2003, 02:51 PM
When you go "back," you should be going back to what was there not loading something new.&nbsp;

The example that I gave above (guaranteed fresh) will actually force a reload if you go back after more than 60 seconds.&nbsp; Change the timer if you want something less.

10-15-2003, 05:54 PM
That's quite right - when you go back in Opera it doesn't reload the page, it shows you literally what you were just looking at as a snapshot. This is the correct way, and also better in practise, since it means that going back uses almost no browser resources, compared to having to reload the page.

But are there are practical disadvantages - some functions aren't executed; the window.onload event doesn't fire again.

It's been debated heavily on the O7 mailing list, and I doubt very much whether this behavior will change. As it is, it's a happy state of affairs most of the time except that the occassional bit of javascript breaks. But to change it could mean that all pages are slower, all the time. You can see how it's not such a bad trade off in those terms :)