Opera8 xml problem??

Forums » General Opera topics » Open the Web

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

24. April 2005, 09:34:36

bloodycapes

Posts: 26

Opera8 xml problem??

Okay I just upgraded from Opera 8 beta 3 to Opera 8 final and now on a certain site I visit I see that I have an xml problem that I cant view it. I never had that problem on another other version of opera or the beta 8 version. I am forced to use I.E. evertime I am on that site. I dont like I.E. at all and that is why I moved to opera. Now can someone tell me how I can either fix this issue or any plug ins I can get that will work around it. I did a search but nothing correct came up. Thank you.

24. April 2005, 09:50:19

samuil

Posts: 64

Well, it is site problem, and I don't know if you can easily fix it. XML parsing errors show up only when http server sends header with content-type: application/xml. Opera assumes that if someone bothered to configure server to send such header, he also bothered to create well-formed xml site.
Probably your problem can be fixed with some proxy, ie. Proximitron, but I never used one of those so I can't be sure they can do that.
--
Regards,
samuil

sorry for my english...

24. April 2005, 14:05:22

Opera Software

haavard

Desktop QA

Posts: 16056

Please remember to include the URL when reporting problems with a page.
The Opera Ninja recommends a forum search to find answers to your questions ninja

Håvard Kvam Moen @ My Opera / Twitter

24. April 2005, 20:14:12

bloodycapes

Posts: 26

Well its myspace.com and its the band profiles. I use to be able to view the songs on the band profile which use XML with Opera with out a problem but now with the final version of Opera 8 it does not work. What first happends is it says loading XML file then I get the Incorrect Input File message. browser at all. Now I know that site has a bunch of code erros and what not that cause the site to mess up like every week; but I know its not a site problem because the band pages work well in internet explorer which bothers me since I am a big opera fan since version 6.

25. April 2005, 20:53:55

neeraj_deshmukh

The Falcon

Posts: 21593

You did not specify an actual URL where you see the problem, so naturally you did not get any more response. I had to dig through an unfamiliar web site to find a page where I could see the problem -- you could have saved me the trouble by being a bit more helpful.

The problem is with the page code. Here's an example URL -- http://www.myspace.com/stephaniedosen

The code implementing the Flash-based media player is as follows:
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH="450" HEIGHT="345" id="mp3player" ALIGN="" border=0>
 <PARAM NAME=movie VALUE=[b]"http://music.myspace.com/index.cfm?fuseaction=music.player&xmlfid=8787151&siteurl=http://music.myspace.com/&Mytoken=20050425133941"[/b]>
 <PARAM NAME=quality VALUE=high>
    
 <EMBED src=[b]"http://music.myspace.com/index.cfm?fuseaction=music.player&Mytoken=20050425133941"[/b] quality=high bgcolor=#FFFFFF WIDTH="450" HEIGHT="345" NAME="mp3player" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
Note that the embed tag has an incorrect file name. If that is fixed to match the file name in the object tag, your media will play just fine.
Opera 10.0 (build 1589) * JRE 6.0u13 * Flash 10,0,22,87 * Dell Latitude D630 * Windows XP Pro SP3 * 2.5GHz Core 2 Duo * 2GB RAM
Never argue with an idiot. They drag you down to their level, then beat you with experience. - Dilbert

27. April 2005, 07:39:45

bloodycapes

Posts: 26

well the problem I explained was happening with a profile that had xml music page so pretty much all you had to do was click music on the main page type in the name of a band you like and click on there profile and there is where I see the problem. Like for example this one here http://www.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=769597&Mytoken=20050427003818

27. April 2005, 08:15:36

Opera Software

hallvors

Opera Software

Posts: 1776

I contacted them through their form, asking them to fix the problem in the code.
I also moved this thread to the Open The Web category. Thanks for noticing the problem.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

27. April 2005, 08:35:22

burnout426

Posts: 12424

In addition to neeraj_deshmukh's post...

Yeh, it works fine like this in Opera. That's all Opera needs to play it, so it's not like it's hard to support Opera.

27. April 2005, 23:09:38

bloodycapes

Posts: 26

well its not only that band its every band on that site and burnout how did you do that?

28. April 2005, 06:38:32

burnout426

Posts: 12424

I got rid of all the microsoft activeX crap and the embed crap.

Then just used the data attribute to load the proper file and set the type attribute to specificy the proper mime type.

However, as already said, the way that the object tag is currently set up on the site, Opera falls back on the embed tag and the embed tag source is not correct. It's different from the src specified for the object tag.

It's all probably done server-side, so if they fix the problem, it should be fixed for all bands.

29. April 2005, 05:09:13

bloodycapes

Posts: 26

well I get what your saying now but the odd part is it works with IE and Firefox. But I will suggest them to make it more opera compatable i guess.

29. April 2005, 12:48:39

burnout426

Posts: 12424

They don't work in Firefox or even Opera 8 beta 3 for me. (but other flash does) They do the same as Opera 8 and don't load. Both Firefox and Opera are falling back on the embed tag, which has the wrong URI. They fall back because the object tag is not setup right. It's setup to load the movie with the flash plugin, via ActiveX, which only IE supports.

<object data="" type="" >
    <param name="" value="" valuetype="" />
    <div>Alternate text</div>
</object>


data: Where you specify the file to load

type: Where you specify the mime type, which determines what plugin is used to load the file.

codebase: Where you specify a base uri to resolve relative paths in the data and clsid attributes.

clsid: Where you can specify a URI that specifes the implementation for the object

param-name: Where you specify the name of the param the file in data="" uses
param-name: Where you specify the value for the paramamter
param-valuetype: Where you specify the type for the paramater, data/ref/object
param-type: Where you specify the mime type of the param (if it's of type ref)

You also have the option of displaying alternate content if the plugin doesn't initialize or the movie can't be loaded.

Because of ActivX, they really abuse what classid an codebase are for.

Anyway, they don't need to make it more Opera compatible. They just need to do it right and it'll work or at least make the embed tag src be the same as the movie param value.

If the IE method of using the object tag is working in Firefox, it's most likey that the devs added some kind of handling to guess what to do.

Of course, if you do it the right way, in IE, it'll work with basic things, but when the movie has to load something else, it doesn't always work, which is why they first make it work in IE and then allow other browses to fallback on the embed tag, which of course will work if the URI is right.

I suppose if Opera sees the classid and recognizes it as flash, it could be made to look for a movie URI in one of the param tags and use that to load, but it embedding already works if you do it right.

29. April 2005, 15:56:26

bloodycapes

Posts: 26

Well I guess the firefox people did something to make it work right since it was working for me in Firefox on my Apple OSX machine and a friends XP machine with firefox. I will what the site manager/owner has to say. Myabe there is a Opera plug-in for this type of situation? Thank you very much though.

29. April 2005, 17:12:09

burnout426

Posts: 12424

Firefox 1.0.3 - WinXP SP2

Examples of ones that don't work for me in Firefox
http://www.myspace.com/stephaniedosen
http://www.myspace.com/mindshift
http://www.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=769597&Mytoken=20050427003818

I decided to try them in IE too. It starts the player, but doesn't load the xml file.

Example of flash that works in *my* IE, Firefox and Opera


Now, I've been to myspace not to long ago and everything worked fine, in IE,Firefox and Opera. Not sure

I don't know whether earlier versions of Firefox work on myspace right now, but I'll have to check.

You of course could always forget the embedding and just load the flash directly till they fix it.

30. April 2005, 08:33:07

bloodycapes

Posts: 26

It was kinda odd since I had no problem viewing myspace with B3 of Opera 8. Also those bands work for me in Firefox odd.

30. April 2005, 16:53:25

burnout426

Posts: 12424

Originally posted by bloodycapes
It was kinda odd since I had no problem viewing myspace with B3 of Opera 8. Also those bands work for me in Firefox odd.



It is odd, but I'm not saying they didn't work for you in Firefox and 8 beta 3. I'm just saying for me, they don't now.

Everything use to work O.K. there, so I think they changed something.

30. April 2005, 16:58:58

burnout426

Posts: 12424

Originally posted by Sigup
Why is this in open the web?



IMO, it's here because this is something the webmaster of myspace needs to fix. However, if there is indeed a bug, I'll report it. I myself just haven't been able to determine for sure if it's a bug as it's not working for me in any browser.

To add to that, neeraj_deshmukh already described how it can be fixed and I also showed how easy it was to get it to work in Opera specifically. Plus, hallvors contacted them with the idea that it was a problem with the site.

1. May 2005, 10:31:49

Opera Software

hallvors

Opera Software

Posts: 1776

1) Is this OTW? IMO yes:

The website has made a simple coding mistake: the "fallback" content for browsers that do not understand their OBJECT tag is broken. That's why it is an Open The Web-issue. It is in the site's best interest to fix this because it will make their site more cross-browser compatible, and I have told them so.

2) Is it a bug? Should Opera change to handle this code?
IMO maybe: Opera already tries hard to understand the OBJECT even when some information is missing (specifically, the OBJECT tag should always have DATA and TYPE attributes). It is tricky to always get it right, and some "magic" that perhaps made this page work in beta 3 caused other problems and had to be removed. Perhaps it will come back...
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

2. May 2005, 08:07:49 (edited)

burnout426

Posts: 12424

Site problems aside, perhaps, Opera could improve the handling by doing something like this (as an example)

If !object.data, try to get the URI to the file from the param["src"].value or the param["movie"].value.

If !object.type, try to get the type from param["src"].type or param["movie"].type. If that doesn't work, and the classid attribute exists, try to use it to determine the type. (There'd be an internal list of known classids and there mimetypes). If that doesn't work, try to use the extension of the determined source to determine the mime type.

If all of that fails, then display alternate content.

Also, if the data attribute and or the type attribute does exist, but the init fails, Opera could try the secondary methods.

No sense in going overboard to handle poor code, but improving handling in general would definitely be nice.

Edit:

Here's a code example (descriptive purposes only) of what I suggest.

bool src_exists = true;
bool using_movie = false;

if ( object.data.empty() ) {
    if ( object.hasParam("src") && !object.param["src"].value.empty() ) {
        object.data = object.param["src"].value;
    } else if (object.hasParam("movie") && !object.param["movie"].value.empty() ) {
        object.data = object.param["movie"].value;
        using_movie = true;
    } else {
        src_exists = false;
    }
}

bool type_exists = true;
if ( object.type.empty() ) {
    if ( object.hasParam("src") && !object.param["src"].type.empty() && !using_movie) {
        object.type = object.param["src"].type;
    } else if (object.hasParam("movie") && !object.param["movie"].value.empty() && using_movie) {
        object.type = object.param["movie"].type;
    } else if ( !object.classid.empty() && classid_list.hasEntry(object.classid) ) {
        object.type = classid_list.item(object.classid);
    } else {
        type_exists = false;
    }
}

if (src_exists && type_exists) {
    object.init();
}

2. May 2005, 09:30:18

Opera Software

hallvors

Opera Software

Posts: 1776

The problem is how far ahead in the source you should go looking for PARAMs. Sometimes object close tag is missing or improperly nested.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

3. May 2005, 01:23:43 (edited)

burnout426

Posts: 12424

Good question. smile

I think we could just do it with user.js and search through the param array for each object. I've something brewing and if it works out, I'll post the user.js.

3. May 2005, 06:03:15

burnout426

Posts: 12424

Here's my first attempt of using user.js to improve object tag handling. It's enough to at least make myspace.com work. (once the page is finished loading, Opera will fix the bad code in the page).

document.addEventListener("load", function () {
    var obj = document.getElementsByTagName("object");
    for (var i = 0; i < obj.length; i++) {
        var param = obj[i].getElementsByTagName("param");
        for (var c = 0; c < param.length; c++) {
            if ( (!obj[i].data || !obj[i].type) && (param[c].getAttribute("name").toLowerCase() == "src" || param[c].getAttribute("name").toLowerCase() == "movie") ) {
                if (!obj[i].data) {
                    obj[i].data = param[c].getAttribute("value");
                }
                if (!obj[i].type) {
                    obj[i].type = param[c].getAttribute("type");
                }
                break;
            }
        }
        if (!obj[i].type && obj[i].getAttribute("classid") ) {
            var id = obj[i].getAttribute("classid");
            if (id == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000") {
                obj[i].type = "application/x-shockwave-flash";
            }
        }
        if (!obj[i].type && obj[i].data.substring( obj[i].data.lastIndexOf(".") , obj[i].data.length) == ".swf") {
            obj[i].type = "application/x-shockwave-flash";
        }
    }
}, false);


If the type attribute is empty or doesn't exist, the code tries to get the type from the type attribute of a movie or src param. If that doesn't work, it tries to get the type via the classid. If that doesn't work, it tries to get the type by the extension in the source URI.

If the data attribute is empty or doesn't exist, the code tries to get the src from a movie or src param.

The code only includes one classid check (for flash), but more could be added.

If someone wants to give an example of how I could have a map of classids and their values, and how I can search that map for a match, that would be cool.

And of course if Andrew wants to clean the code up, I'm all for it.

3. May 2005, 07:13:45

You called? bigsmile

It looks pretty good to me. I'd change just the one line:
if (!obj[i].type && obj[i].data.substring( obj[i].data.lastIndexOf(".") ).toLowerCase() == ".swf") {
(remove unnecessary second substring parameter, add toLowerCase)

As for mapping classid to types:
var types = new Object();
types['clsid:[b][/b]D27CDB6E-AE6D-11cf-96B8-444553540000'] = 'application/x-shockwave-flash';
type = types[getAttribute('classid')];
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

3. May 2005, 20:15:26 (edited)

burnout426

Posts: 12424

Thanks, that helps.
Here's the basis of what I was thinking:

document.addEventListener("load", function () {
    var types = new Object();
    types['clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'] = 'application/x-shockwave-flash';
    types['clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b'] = 'video/quicktime';
    types['clsid:663c8fef-1ef9-11cf-a3db-080036f12502'] = 'application/x-java-applet';
    types['clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa'] = 'audio/x-pn-realaudio-plugin';
    types['clsid:166b1bca-3f9c-11cf-8075-444553540000'] = 'application/x-director';
    types['clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'] = 'application/x-mplayer2';
    var exts = new Object();
    exts['.swf'] = 'application/x-shockwave-flash';
    exts['.rpm'] = 'audio/x-pn-realaudio-plugin';
    exts['.class'] = 'application/x-java-applet';
    exts['.mov'] = 'video/quicktime';
    exts['.dcr'] = 'application/x-director';
    var obj = document.getElementsByTagName("object");
    for (var i = 0; i < obj.length; i++) {
        var param = obj[i].getElementsByTagName("param");
        for (var c = 0; c < param.length; c++) {
            if ( (!obj[i].data || !obj[i].type) && (param[c].getAttribute("name").toLowerCase() == "src" || param[c].getAttribute("name").toLowerCase() == "movie") ) {
                if (!obj[i].data) {
                    obj[i].data = param[c].getAttribute("value");
                }
                if (!obj[i].type) {
                    obj[i].type = param[c].getAttribute("type");
                }
                break;
            }
        }
        if (!obj[i].type) {
            obj[i].type = types[ obj[i].getAttribute("classid").toLowerCase() ];
        }
        if (!obj[i].type ) {
            obj[i].type = exts[ obj[i].data.substring( obj[i].data.lastIndexOf(".") ).toLowerCase() ];
        }
    }
}, false);


* For the last two conditionals, I didn't check to make sure the things were not undefined first. JS let's you get away with trying to assign something undefined.

@hallvors

If we can do that with js, it seems that something like that could be done internally as long as you wait till all the child nodes for the object tag are determined or possibly (to be more efficient) only try it if it fails to init.

3. May 2005, 14:19:23

Here's an idea devil

Use the navigator.mimeTypes collection to map extensions to types (perhaps build the exts array automatically):
mts = navigator.mimeTypes;
for (i = 0; i < mts.length; i++) {
  opera.postError(mts[i].suffixes + ':' + mts[i].type);
}
(there are two other properties besides "suffixes" and "type": "description" and "enabledPlugin")

BTW, the "mov" and "dcr" extensions seem to be missing a ".".
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

3. May 2005, 20:38:03

burnout426

Posts: 12424

Fixed the 2 movie types. (added the '.');

I'll investigate using the mime.types array for the extensions. Thanks.

For the whole exts part, if no type is specified, Opera already tries to use the mime type of the file specified by the server and if that's not correct, Opera tries to determine the action by the extension. (If the now hidden file types setting is at default). So Opera already does a decent job of trying to find the type. However, there are situations where that doesn't work, so the exts part in the user.js might help for situations like that.

5. May 2005, 01:12:00

burnout426

Posts: 12424

O.K., I'm searching navigator.mimeTypes suffixes for an instance of the extension. The object type gets set to the first mimetype that lists the extension.

// Try to load objects that don't have a data/type attribute set for it
document.addEventListener("load", function () {
    var types = new Object();
    types['clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'] = 'application/x-shockwave-flash';
    types['clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b'] = 'video/quicktime';
    types['clsid:663c8fef-1ef9-11cf-a3db-080036f12502'] = 'application/x-java-applet';
    types['clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa'] = 'audio/x-pn-realaudio-plugin';
    types['clsid:166b1bca-3f9c-11cf-8075-444553540000'] = 'application/x-director';
    types['clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'] = 'application/x-mplayer2';
    var mtl = navigator.mimeTypes;
    var obj = document.getElementsByTagName("object");
    for (var i = 0; i < obj.length; i++) {
        var param = obj[i].getElementsByTagName("param");
        for (var c = 0; c < param.length; c++) {
            // First try to get the source/type from a movie or src param. 
            if ( (!obj[i].data || !obj[i].type) && (param[c].getAttribute("name").toLowerCase() == "src" || param[c].getAttribute("name").toLowerCase() == "movie") ) {
                if (!obj[i].data) {
                    obj[i].data = param[c].getAttribute("value");
                }
                if (!obj[i].type) {
                    obj[i].type = param[c].getAttribute("type");
                }
                break;
            }
        }
        // If a source has been found, but still no type.
        if (obj[i].data && !obj[i].type ) {
            // Try to determine type from the classid attribute.
            obj[i].type = types[ obj[i].getAttribute("classid").toLowerCase() ];

            // If type still not found, try to determine the type from the extension of the source.
            if (!obj[i].type ) {
                for (var m = 0; m < mtl.length; m++) {
                    if (mtl[m].suffixes.indexOf( obj[i].data.substring( obj[i].data.lastIndexOf(".") + 1 ).toLowerCase() ) != -1) {
                        object.type = mtl[m].type;
                        break;
                    }    
                }
            }
        }
    }
}, false);

6. May 2005, 14:11:22

@burnout426: That script is looking pretty nice now!
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

6. May 2005, 14:40:20

mr7clay

Posts: 38

MySpace music player bookmarklet

Originally posted by neeraj_deshmukh
Note that the embed tag has an incorrect file name. If that is fixed to match the file name in the object tag, your media will play just fine.


I made a bookmarklet to workaround this issue. It opens the MySpace music player in a new window. I suppose it could be modified to simply fix the problem, too.

7. May 2005, 07:16:09 (edited)

burnout426

Posts: 12424

^^ Thanks, although bookmarklets only work if you have "reuse existing page" set.

Edit: looks like there's a way

Originally posted by Andrew Gregory
@burnout426: That script is looking pretty nice now!



Thanks for the help.

The script could probably be quickly optimized a little like

for (var i = 0; i < obj.length; i++) {
    if (obj[i].data && ojb[i].type) {
        continue;
    }
    // rest of code


to skip the assigning of param and skip entering the parm loop etc. if it's not necessary.

Also, using a nodeiterator might be a little faster as opposed to incrementing an index. Using iterators in c++ can be faster, but not sure with Oprea and js.

9. May 2005, 07:55:13

burnout426

Posts: 12424

Oops, I notice an error I had in the last conditional.

object.type = mtl[m].type;
That should be obj.type = mtl[m].type;

19. May 2005, 13:03:59

virtuelvis

Posts: 137

burnout426: This script is excellent work. Mind submitting it to the UserJS.org site for User JavaScripts? See this thread for more information.
Arve

Opera Software ASA.

19. May 2005, 19:13:29

burnout426

Posts: 12424

I saw your thread before. I wa already thinkin about it.

The script needs to be a little smarter first. I've encounter some width/height situations when it comes to to tags with embed as a fallback that I need to fix.

21. May 2005, 13:02:15

trez260

Posts: 5

i'm having the exact same problem with myspace (ref: http://www.myspace.com/trez) in Opera the player does come up but instead of the tracklist it says "Incorrect Input File" I was initially using Firefox, but after reformating my hard drive, when accessing myspace with Firefox it only showed the Quicktime "Q"

My apologies for sounding redundant, however this is a area i'm not familiar with at all. i see where where you can place your JavaScript Files from the tools>preference>advanced>content>javascript options.

what script can be used so that it is fairly universal. what editor to use so can save the script as a .js file. in the tutorial (i attempted to read and understand most of it) it has 4 methods, should all 4 types of scripts be in folder where Opera is to access?

21. May 2005, 13:48:57

Opera Software

hallvors

Opera Software

Posts: 1776

You didnt mention what operating system you use, so i will assume windows. First copy the script and paste it in notepad. Choose "file -> save" and put quotes around the name to prevent notepad from adding .txt . You could call it for instance objectfix.js . Now save it to the folder you have chosen in js preferences.
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

21. May 2005, 14:00:47

trez260

Posts: 5

my fault. windows xp pro. is there a particular script that i should use? i have yet to find a script to correct my problem.

21. May 2005, 21:37:11

Opera Software

hallvors

Opera Software

Posts: 1776

Originally posted by trez260
my fault. windows xp pro. is there a particular script that i should use? i have yet to find a script to correct my problem.



The script written by Burnout426 and posted above should work. For your convenience I have attached it (though the .txt extension needs to be changed to .js) and fixed the typo Burnout426 pointed out a few posts before this one..

So, you can just open this file in Opera, use "Save as", put it in your User JS folder and change the extension to .js. (Opera may not allow you to do that from the save as dialog, not sure.)

objectfix.txt
--
My blog: miscoded
Stupid code from major websites uncovered and criticised
Contribute site fixes! - OTW&TA- all sites must work

21. May 2005, 21:45:55

trez260

Posts: 5

much appreciated. Peace.

22. May 2005, 00:25:48

Just wantede to add my 2 cents and say that My Space worked in Firefox and in IE for me but doesn't in Opera.

I also get the incorrect input file message.

22. May 2005, 05:12:17

burnout426

Posts: 12424

Yeh, I previously said that it didn't work in IE and Firefox for me, but I forgot to allow cookies for myspace.com.

For comparison, purevolume.com works fine in Opera. purevolume.com and myspace.com both use a flash player to play the songs. They both use the same coding methods to embed the flash. The difference is that myspace.com made a mistake and put the wrong URI in the src attribute for the embed tag.

It works in IE because the object tag is setup in a way that only IE understands.

For Firefox, I need to check the source, but it seems the developers added handling to make broken code like myspace.com's work.

22. May 2005, 11:43:43

burnout426

Posts: 12424

Here's a newer version of the user js to improve object tag handling that I am messing/testing with.

For this one, if the object tag doesn't have a width or height, it looks for a width or height param. Case where that helps.

This version doesn't give up trying to find a source after it encounters the first movie/src param. It keeps trying. Before, it would try to use a src/movie param and quit. Now, if the src param didn't work, it'd try the movie param etc.

Also, for this version, I used hasAttribute(), setAttribute() and getAttribute() all the way through.

I better explain my setup for the conditionals in this one:

I check to make sure an object exists before checking to see if it has an attribute. I then check to see if it has the attribute before I actually get the attribute.

For example, I don't like doing something like this:

if (obj[i] && obj[i].hasAttribute("width")) {
    // do something
}


Although that works fine, if obj doesn't exist, I shouldn't be checking to see if it has an attribute; even if js allows that or the interpreter translates that to the following, which I like better.

if (obj[i]) {
    if (obj[i].hasAttribute("width")) {
        // do something
    }
}



I'm still testing this one, but so far, it looks like this one is better.

22. May 2005, 12:40:40

With:
if (expr1 && expr2){
if expr1 is false, then the entire expression must be false, and expr2 is ignored. This is in the language definition (called "short circuit boolean evaluation") and can be relied upon. Your first code block is the conventional and safe way of doing that test. Of course, the second code block is also perfectly fine, it just requires more typing.

A similar thing happens with the || operator (if the first expression is true, the entire expression must be true, so following expressions are ignored).
Web Site (Opera pages) : Blog
(currently using Opera 10 and a fairly recent v10.10 alpha)

22. May 2005, 17:53:42

burnout426

Posts: 12424

I do see what you are saying and you are correct. Thanks

I should have worded things a little differently in my explanation as I mixed 2 different issues.

Revision...

I better explain my setup for the conditionals in this one:

This time I added more conditionals. For example, I make sure an object exists before checking to see if it has an attribute. I then check to see if it has the attribute before I actually get the attribute. I could just forget the checks, get the attribute and rely on it being null/undefined if the attribute doesn't exist (like I did in the previous version), but I don't like getting an attribute value if I don't know the attribute exists first. Personal preference / good practice I guess.

In keeping with the same spirit above, for my conditional blocks, I purposely chose not to check for an object and one of its members in the same 'if' statement condition.

For example, I personally don't like doing something like this:

if (obj[i] && obj[i].hasAttribute("width")) {
    // do something
}


Although that works fine and is O.K., Focusing on the second expression itself and forgetting about "short circuit boolean evaluation", it could be undefined if obj doesn't exist. Because of that mindset, I *prefer* to do it like this instead.

if (obj[i]) {
    if (obj[i].hasAttribute("width")) {
        // do something
    }
}


I do realize it can be simplified. Just wanted to explain why I did it like I did so I didn't get a swarm of "you know you can simplify those conditions?".

2. June 2005, 03:47:02

burnout426

Posts: 12424

I've found something a little weird with my user js. It breaks the 2 flash objects here.

It seems like when the script gets a relative URI from a movie or source param, the relative uri doesn't get resolved when I set it as the value of the data attribute. I therefore have to set the codebase attribute to http://www.macromedia.com *before* I set the data attribute value to the movie or source param value.

Basically, to get that specific page to work with my user js, I'd have to change the one part to this:

if ( !obj[i].hasAttribute("data") ) {
    //obj[i].setAttribute("data", param[c].getAttribute("value") );
    obj[i].setAttribute("codebase","http://www.macromedia.com");
    obj[i].setAttribute("data", param[c].getAttribute("value"));
    
}


An odd thing happens when I do that though. The objects load, but right-clicking on them shows "movie not loaded" even though they are.

I've used relative uris with the data atribute before and they work, but the uri was coded in the source. It looks like when you use obj.data = "relative uri" or obj.setAttribute("data","relative uri"), the uri doesn't get resolved like it would if it was coded in the source.

Is that a bug? When I insert a relative uri into the data attribute with JS, should Opera resolve it like it would if it encountered the uri in the source code?

Those 2 objects work fine without the user js, but I wanted to point that out.

Edit:

Nevermind.

Like so many other sites, macromedia is misusing the codebase attribute, which messes up the resolving of the data attribute.

Adding obj.removeAttribute("codebase"); before I set the data attribute fixes the problem in this case. That's not a solution though as what if the codebase attribute was really valid? I think I'll have to check the codebase attribute for common values that misuse the attribute and remove the attribute in that case.

6. June 2005, 03:08:41

ok...so, the code posted, works about every other time with the xml loading the songs(which is better than never, I suppose) but when I go to other sites that have a flash intro or something, the flash doesn't load...when I turn the .js code off, the flash loads fine, but then I can't go back to myspace and listen to the music unless I turn the .js file back on....I'm not a coder so I can't decipher whats going on...hopefully you can help! Oh yea, and just for example, www.limpbizkit.com is on of the sites where the flash intro won't work when the .js myspace fix is active...also www.mtv.com

6. June 2005, 04:29:59

burnout426

Posts: 12424

I think you are experiencing the problem described above.

For now, try the attached version. I tested this version with the mtv and limpbizkit intros. They worked. The fix still works for myspace.com.

You can also add the following to the top of the js file so it only executes for myspace.com (After all, why fix sites that are not broken smile )

// ==UserScript==
// @include [url]http://www.myspace.com/*[/url]
// ==/UserScript==


You can add more include lines too. However, I think there's a bug where only the last include works, but not sure if that still exists. If you encounter that, *for now* just use extra copies of the scirpt with their own include line.

The script is a general script to improve object tag handling. I am thinking about making one specifically for myspace.com, but for now.....

improve_object_tag_handling-fix.zip

6. June 2005, 23:45:31

hey thanks a bunch, I appreciate it!

7. June 2005, 21:53:53

oooooook....I'm back, haha. Well, it works for certain bands on myspace, but not other, like, it works at http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=2132176&Mytoken=20050607144430

But...it doesn't at http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=2132176&Mytoken=20050607144430 and http://www.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=2746475&Mytoken=20050607144430

now...this might be a coincidence, but I notice that the band it does work on is http://profile.myspace.com and the other are just http://myspace.com, don't really know if thats relevant, just something I noticed...once again, any help would be great!! Thanks a bunch...

8. June 2005, 03:13:47

burnout426

Posts: 12424

If you ended up using the include line, try changing it from http://www.myspace.com to just myspace.com or http://myspace.com . If that doesn't help, try 3 separate files with each one having a different include.

http://profile.myspace.com
http://www.myspace.com
http://myspace.com

If you are not using the include stuff, then all I can say is that the script works more often at http://www.myspace.com/mindshift when I don't allow cookies for myspace.com.

I assume that profile.myspace.com requires you to login and use cookies, so you probably won't be able to try it there without cookies.

I've contacted myspace.com many, many times showing them their error and how to fix it, but they won't respond. Opera has contacted them and as far as I know, they have not responded to them either.

I was just going to suggest that you forget about myspace.com and use purevolume.com, but the player at purevolume.com seems to not work sometimes (unless you use always use the user js or open the player in a new window).

Forums » General Opera topics » Open the Web