Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
SuckerPunched
Dec 20, 2006

Ether Frenzy posted:

You can't do a satisfactory image replacement of the submit button (or at least not have it work in IE 6, which we stupidly continue to support - would typically be done with CSS v2) with input type="submit", it has to be input type="button" to use an image as the button.

You could use the <button> tag though, and get what you wanted. <button type="submit">Some Crap</button> should work in IE6, and be styled with CSS just fine as well.

Adbot
ADBOT LOVES YOU

diadem
Sep 20, 2003
eet bugz
I'm looking to force my zoom level to 100% in IE7 and IE8 on one of my sites, but can not find a way to do this. Is this even possible?

If it matters, my IE8 sites all force compatibility mode.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Hammerite posted:

Full disclosure - I posted this in the Web Design & Development small questions thread, but came to the conclusion that it's really more Javascript and I will be more likely to get help with it here. Hence I'm reposting it.

My website implements a board game via PHP. A user can view a game in progress by visiting a URL that looks like mywebsite.com/board.php?GameID=1234. Although the site is essentially set up to enable a play-by-email kind of experience, it might happen that some users would like to play in real time, or close to real time. Because the page generated when visiting the URL is static, they can only see what the real current state of the game is by refreshing the page. This is inconvenient, and it means more work for my website too if people are constantly refreshing pages, so I rigged up a hack to slightly reduce the problem. To each game there corresponds a number saying how many moves have been made in the game. So it starts off at zero and is incremented whenever someone makes a move. If a user loads a page corresponding to a game in progress, then a Javascript runs such that every five seconds the page checks with the website to see if the number of moves made is bigger. If it is then it turns the page background a different colour, so as to alert the user without interrupting any activity the user is performing on the page.

My <body> tag looks like this:

<body onLoad="IntervalID = setInterval ('ajaxFunction()', 5000);" onUnload="clearInterval(IntervalID);">

For completeness, here is ajaxFunction: (This was taken from the page from a game that at the time had had 95 moves made, hence the "95")

code:
function ajaxFunction() {
    /* Attribution: This JavaScript code is based on code
       taken from w3schools.com */
    var xmlHttp;
    try { xmlHttp=new XMLHttpRequest(); }
    catch (e) {
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            return false;
        }
    }
    xmlHttp.onreadystatechange=function() {
        if ( xmlHttp.readyState == 4 ) {
            if ( xmlHttp.responseText != "95" ) {
                document.bgColor = "#BFDFFF";
                clearInterval(IntervalID);
            }
        }
    };
    xmlHttp.open("GET","newmoves.php?GameID=1234",true)
    xmlHttp.send(null);
}
My question: I noticed that occasionally when one leaves the page, the page background will change colour (despite the fact that when one comes back, no new moves have been made). I deduce that this is because the every-five-second function happens to be running at just that time. I attempted to tackle this by adding to the <body> tag (as given above) the following:

onUnload="clearInterval(IntervalID);"

This does not solve the problem. The page still changes colour sometimes when one leaves. What should I do to stop this?

Perhaps make your code > 94? It's possible the ajax return happens when it's false on unload, and since false is not the string 95, you get a background change. This is my pre-coffee first guess, so it's probably wrong. I'll look again in an hour when I wake up.

Also thank's for the reminder as to how ugly "plain" ajax code is. I don't miss writing stuff like that at all. /me gives jQuery a hug.

ronin109
Aug 23, 2002

Ether Frenzy posted:

You can't do a satisfactory image replacement of the submit button (or at least not have it work in IE 6, which we stupidly continue to support - would typically be done with CSS v2) with input type="submit", it has to be input type="button" to use an image as the button.

An input with type="image" will allow you to use an image. An input type="image" works exactly like an input type="submit" except you can now give it an image source.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

Lumpy posted:

Perhaps make your code > 94? It's possible the ajax return happens when it's false on unload, and since false is not the string 95, you get a background change. This is my pre-coffee first guess, so it's probably wrong. I'll look again in an hour when I wake up.

Also thank's for the reminder as to how ugly "plain" ajax code is. I don't miss writing stuff like that at all. /me gives jQuery a hug.
Yeah - I suggest using parseInt first and then if that is successful then do the comparison to your current count.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Lumpy posted:

Perhaps make your code > 94? It's possible the ajax return happens when it's false on unload, and since false is not the string 95, you get a background change. This is my pre-coffee first guess, so it's probably wrong. I'll look again in an hour when I wake up.

Thanks for the suggestion, I'll try making this change.

Of course it's one of those funny things that since I can't make it happen on demand, there's no way of knowing whether it worked unless several weeks go by with no "false positives".

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
What Lumpy said prompted me to carry out the following test: I loaded up a typical board page, then disconnected my computer from its network connection. I then waited a while to see if the page would change colour; then clicked an arbitrary hyperlink on the page so as to exit. By doing this I was consistently able to cause the background colour change to trigger (always upon clicking the hyperlink).

I then changed the code as follows:

code:
function ajaxFunction() {
...
    xmlHttp.onreadystatechange = function() {
        if ( xmlHttp.readyState == 4 ) {
            var p = parseInt(xmlHttp.responseText);
            if ( !p ) { return false; }
            if ( p != 95 ) {
                document.bgColor = "#BFDFFF";
                clearInterval(IntervalID);
            }
        }
    };
...
}
(continuing from the above example where the key value was 95)

I then repeated the test after making this change. The background colour no longer changes on exiting the page. I conclude that the change had the desired effect. Thanks both.

I am puzzled by one thing; in my test (of the old code) I only saw the colour change on clicking a hyperlink. I had thought what might happen would be that it would change colour anywhere between 0 and 5 seconds after disconnecting my computer, but this is not the case.

a powerful frown
Jan 31, 2005

I'm running an old javascript menu I had lying around my computer for years. I wanted the script centered, so modified it to include a margin-left and changed its absolute position which works fine in chrome, opera, IE but breaks in firefox which puts the menu on the far left of the screen

thoughts?

unfortunately, using a div container won't work either

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

FedEx posted:

I'm running an old javascript menu I had lying around my computer for years. I wanted the script centered, so modified it to include a margin-left and changed its absolute position which works fine in chrome, opera, IE but breaks in firefox which puts the menu on the far left of the screen

thoughts?

unfortunately, using a div container won't work either

Guys, something is wrong with my car engine, it's sort of making this noise... I put a clamp on that thing, but now the other hose is lose: what should I do to fix it?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Hammerite posted:


I am puzzled by one thing; in my test (of the old code) I only saw the colour change on clicking a hyperlink. I had thought what might happen would be that it would change colour anywhere between 0 and 5 seconds after disconnecting my computer, but this is not the case.

If you are disconnected form the internet, you cannot get a "good" ready state change event from your function, so the checking code will never run.

a powerful frown
Jan 31, 2005

Lumpy posted:

Guys, something is wrong with my car engine, it's sort of making this noise... I put a clamp on that thing, but now the other hose is lose: what should I do to fix it?

hahahahaha

:(

but it has cross browser opacity.

Nigglypuff
Nov 9, 2006


BUY ME BONESTORM
OR
GO TO HELL
I think Lumpy means to suggest you treat us to a glimpse at the source code.

a powerful frown
Jan 31, 2005

Nigglypuff posted:

I think Lumpy means to suggest you treat us to a glimpse at the source code.

wait, for real?

I was going to do that originally but its like 1600 lines >_> I already wrote an alternative PEACE OUT

Supervillin
Feb 6, 2005

Pillbug

FedEx posted:

wait, for real?

I was going to do that originally but its like 1600 lines >_> I already wrote an alternative PEACE OUT

If your JS menu was 1600 lines then it's drat good you wrote an alternative :)

dimebag dinkman
Feb 20, 2003

ronin109 posted:

An input with type="image" will allow you to use an image. An input type="image" works exactly like an input type="submit" except you can now give it an image source.
Not exactly. When you click on an image submit with name "myimagesubmit", it is apparently optional for the browser to submit the myimagesubmit=value key/value pair in the form data, and instead only send the mouse click co-ordinates myimagesubmit.x and myimagesubmit.y. Older versions of IE choose to take the option of not doing so.

quote:

You could use the <button> tag though, and get what you wanted. <button type="submit">Some Crap</button> should work in IE6, and be styled with CSS just fine as well.
Unfortunately in IE6, if you have multiple <button type="submit">s on the same page, it will submit all of them not just the one you clicked on. And the value will be the HTML inside it, not the value="..." attribute.

dimebag dinkman fucked around with this message at 17:06 on Jul 14, 2009

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
There's a javascript workaround for multiple buttons in IE6 http://www.kopz.org/public/documents/css/multiple_buttons_ie_workaround.html

SuckerPunched
Dec 20, 2006

dimebag dinkman posted:

And the value will be the HTML inside it, not the value="..." attribute.

I don't know how to work around the first limitation (sans-javascript), but you could just use CSS to style the button and put whatever relevant value you want in the button tag.

<button type="submit" id="submitter">MyValue</button>

and hide it with CSS text-indent

#submitter { background: transparent url('/path/to/image.png') no-repeat; border: 0; text-indent: -999em; }

ronin109
Aug 23, 2002

dimebag dinkman posted:

Not exactly. When you click on an image submit with name "myimagesubmit", it is apparently optional for the browser to submit the myimagesubmit=value key/value pair in the form data, and instead only send the mouse click co-ordinates myimagesubmit.x and myimagesubmit.y. Older versions of IE choose to take the option of not doing so.

What Ether Frenzy needed was a button that could (a) contain an image, and (b) submit it's parent form (without the use of JS).

An input with type="image" does that. Whether the input sends x/y coordinates or a name/value pair is of no significance in this case.

Save the whales
Aug 31, 2004

by T. Finn

ronin109 posted:

What Ether Frenzy needed was a button that could (a) contain an image, and (b) submit it's parent form (without the use of JS).

An input with type="image" does that. Whether the input sends x/y coordinates or a name/value pair is of no significance in this case.

Doesn't this have the same effect? (except not having the user see "mysubmit.x=20&mysubmit.y=30")

code:
<input type="submit" style="border:none;width:[foo]px;height:[bar]px;background-image: url('[baz]');" value="" />

ronin109
Aug 23, 2002

Save the whales posted:

Doesn't this have the same effect? (except not having the user see "mysubmit.x=20&mysubmit.y=30")

code:
<input type="submit" style="border:none;width:[foo]px;height:[bar]px;background-image: url('[baz]');" value="" />

For some reason, I had it in my head that this wouldn't work in IE6, but, your solution works exactly as expected. This is definitely how it should be done. Your solution has the added benefit of keeping the page-formatting logic in the CSS, where it belongs, unlike type="image" where you are forced to put the image src in a tag attribute.

Just one teeny-tiny addition to your solution would be the inclusion of "background-color: transparent".

sonic bed head
Dec 18, 2003

this is naturual, baby!
I am trying to write some animation javascript code that will make it look like there was suddenly gravity and every element is falling to the bottom of the page. I have no idea where to start with this. I've tried using prototype's absolutize on all of the elements in the body of the page, but that doesn't work. Can anyone give me any advice on where to start? I have no idea of 2D physics but I don't really know where to learn anything. Thanks.

Nigglypuff
Nov 9, 2006


BUY ME BONESTORM
OR
GO TO HELL
You might start by viewing the source of this.

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!
Also, Someone ported the Box2D physics engine to JavaScript.

diadem
Sep 20, 2003
eet bugz
How do you detect if the current window has focus?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

diadem posted:

How do you detect if the current window has focus?

Listen for the onFocus event / onBlur and set a flag.

Here's a poor example that uses a global variable and the not preferred way of doing event handlers to give you the gist:

code:

var iHaveFocus = true;
window.onFocus = 'iHaveFocus = true';
window.onBlur = 'iHaveFocus = false';

function onlyRunIfWindowIsFocused()
{
 if(iHaveFocus)
 {
   // do stuff because the window is focused.
 }
}

diadem
Sep 20, 2003
eet bugz
Thanks lumpy. I tried a few variations of this, but still have no go. I'll keep at it.

Save the whales
Aug 31, 2004

by T. Finn

ronin109 posted:

Just one teeny-tiny addition to your solution would be the inclusion of "background-color: transparent".

Ah, right... drat rounded buttons. I must have missed SuckerPunched's post when I made mine because he included that part. His is nice too because it's still usable when they don't load your stylesheet for some reason, although it's missing the width/height attributes on the button. The only thing I'm not sure of is what happens when the height of the image is less than the height of the text. Although the text is being indented out of view and the height attribute is fixed, would it still stretch to fit the text? I don't have all the major browsers available to me right now so I'm not sure.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I have a problem with the Google Maps API and displaying KML files. The file is valid KML and displays fine if I put the URL into maps.google.com, however, if I go like this on my own site:

code:
map.clearOverlays();
map.addOverlay(GGeoXml("http://domain/path/to/file.kml"));
Nothing shows on the map. If I try to run the functions in Safari's Inspector console, I get:

code:
> map.addOverlay(GGeoXml("http://domain/path/to/file.kml"));
  null
  TypeError: Result of expression 'e.lk' [undefined] is not a function.
e.lk is in Google's mod_kml_api.js file. Anyone have experience with this?

sonic bed head
Dec 18, 2003

this is naturual, baby!

Nigglypuff posted:

You might start by viewing the source of this.


savetheclocktower posted:

Also, Someone ported the Box2D physics engine to JavaScript.

Thank you both! That's exactly what I needed. The google gravity thing actually uses box2d so it's a good practical example.

SuckerPunched
Dec 20, 2006

Save the whales posted:

Although the text is being indented out of view and the height attribute is fixed, would it still stretch to fit the text? I don't have all the major browsers available to me right now so I'm not sure.

If you give it a width, the button will be that width regardless of how much the text is, because it's indented.

Supervillin
Feb 6, 2005

Pillbug

Carthag posted:

code:
map.addOverlay(GGeoXml("http://domain/path/to/file.kml"));
should be
code:
map.addOverlay(new GGeoXml("http://domain/path/to/file.kml"));
GGeoXml is a constructor, you have to use new.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Supervillin posted:

should be
code:
map.addOverlay(new GGeoXml("http://domain/path/to/file.kml"));
GGeoXml is a constructor, you have to use new.

Geez, I looked at that drat thing so long I went blind. Thanks, it works as advertised now :)

Fehler
Dec 14, 2004

.
Is there any way I can allow an iframe to call a Javascript function in the parent window if it is on a different host? I'm getting something like "Permission denied for <http://host1> to get property Window.func from <http://host2>." in my console.

Nigglypuff
Nov 9, 2006


BUY ME BONESTORM
OR
GO TO HELL

Fehler posted:

Is there any way I can allow an iframe to call a Javascript function in the parent window if it is on a different host? I'm getting something like "Permission denied for <http://host1> to get property Window.func from <http://host2>." in my console.

Short answer: no.

Long answer: the frames *can* communicate with each other, but cannot directly call functions or retrieve variables.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I'm dynamically adding a .js file to the header of a page, the .js file is out of my control so I cannot change it.

The last thing it does is register an event listener like so:
code:
window.addEventListener("load", initializationStuff, false);
Since the window is already loaded, the event doesn't fire, but I want it to. I've tried
code:
var event = document.createEvent(); 
event.initEvent('load'); 
document.dispatchEvent(event);
but that gave me a NOT_SUPPORTED_ERR.

Am I doing it wrong? I tried googling a bit and there doesn't seem to be a way in DOM to check if any events are registered, so I cannot check if it's actually set up are not, is that correct?

edit: NM I'm retarded at javascript. I figured it out (it should be createEvent("HTMLEvents"))

Carthag Tuek fucked around with this message at 00:22 on Aug 8, 2009

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Why not call initializationStuff yourself? No need to muck about with events because the DOM has already been initialized.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Mercator posted:

Why not call initializationStuff yourself? No need to muck about with events because the DOM has already been initialized.
I tried but it said undefined, probably cause it's a function reference that gets passed to the event handler. The js file is weird like that, the whole thing is wrapped in an unnamed function as well.

Anyway, this is what I was working on, a greasemonkey script that makes youtube no longer require flash:

http://userscripts.org/topics/32424

If someone wants to run with it, go ahead.

a powerful frown
Jan 31, 2005

I have another small question, I have a javascript element loading on a page. right now it is calculating where the element loads like this:
code:
var left=($(window).width()-(m1.offsetx-$(document).scrollLeft())>m1.actualwidth)? m1.offsetx : m1.offsetx-m1.actualwidth+m1.anchorwidth
which, well, works... but if the window gets resized it isn't in the right position (which sucks). is there any easy way to use the "50%-#px" as one would center in CSS with JS? basically what I want is something that dynamically centers at an offset

edit: copied the code calculating the y offset by accident!

a powerful frown fucked around with this message at 03:36 on Aug 23, 2009

Ned
May 23, 2002

by Hand Knit
Can you turn it into a function that you call on load and on resize?

Adbot
ADBOT LOVES YOU

a powerful frown
Jan 31, 2005

that sounded like a good idea but a lot of work so instead of doing that I just added a style to the css and got the JS to call that for its draw function! except it still only takes either the left: or margin-left:, not both. is there any way to fix that?

a powerful frown fucked around with this message at 04:09 on Aug 24, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply