# Odd js behavior in Chrome & Safari

**URL:** <https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316>\
**Category:** Rails\
**Created:** [December 24, 2008, 11:49am UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316 "2008-12-24T11:49:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 24, 2008, 11:49am UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/1 "2008-12-24T11:49:34Z")

</div>

View file has a js function “confirm\_result()” in section:

The section has

Works just fine in IE7 and FireFox3.

But not in Chrome 1 or Safari 3. In the latter two the confirm box  
appears, then a new blank page without the “You selected…” text. Js  
otherwise working fine

Has anyone else encountered this? Bug in Rails? Chrome? Safari?

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 24, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/2 "2008-12-24T12:22:02Z")

</div>

this obviously ain’t a bug in rails, as there is not a single line of  
ruby/rails-code involved.

why it won’t work in chrome or safari i cannot say.

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 24, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/3 "2008-12-24T16:45:11Z")

</div>

Ken W. wrote:

> View file has a js function “confirm\_result()” in section:
> 
> The section has
> 
> Works just fine in IE7 and FireFox3.
> 
> But not in Chrome 1 or Safari 3. In the latter two the confirm box  
> appears, then a new blank page without the “You selected…” text. Js  
> otherwise working fine
> 
> Has anyone else encountered this? Bug in Rails? Chrome? Safari?

Is this written in RoR? If it is the form helper has an :onsubmit  
attribute that could be useed to call that JavaScript function and I  
would be willing to bet that it would work then. I have had issues with  
Safari and Chrome as well but not concerning forms and JavaScript  
popups.

A quick search led me to this site which shows how to use the :onsubmit  
attribute:

[http://railsforum.com/viewtopic.php?id=19539](http://railsforum.com/viewtopic.php?id=19539)

Good luck,

-S

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 25, 2008, 7:45am UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/4 "2008-12-25T07:45:22Z")

</div>

Tried the “onsubmit”.

Didn’t help.

I think it’s a bug in both Google Chrome and Safari.

Anyone else encountered the same thing?

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [December 25, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/5 "2008-12-25T13:28:53Z")

</div>

> Tried the “onsubmit”.
> 
> Didn’t help.
> 
> I think it’s a bug in both Google Chrome and Safari.
> 
> Anyone else encountered the same thing?

[https://bugs.webkit.org/show\_bug.cgi?id=8961](https://bugs.webkit.org/show_bug.cgi?id=8961)  
[https://bugs.webkit.org/show\_bug.cgi?id=14709](https://bugs.webkit.org/show_bug.cgi?id=14709)

Are you sure you want to use document.write instead of some DOM  
manipulation?

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![kenwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e274bd/32.png) [@kenwei](https://www.ruby-forum.com/u/kenwei)\
**Post date:** [February 14, 2009, 11:13am UTC](https://www.ruby-forum.com/t/odd-js-behavior-in-chrome-safari/156316/6 "2009-02-14T11:13:32Z")

</div>

I ran into this same issue, it has nothing to do with Rails. This  
looks to be an issue with the way WebKit (used by Safari and Chrome)  
handles javascript and form submits. Looks like if there is a onclick  
on a submit button, data from the form is not submitted when the page  
is posted.

On Dec 24 2008, 2:49 am, Ken W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
