View previous topic :: View next topic |
Author |
Message |
Vieri l33t
Joined: 18 Dec 2005 Posts: 882
|
Posted: Fri Feb 02, 2018 12:14 pm Post subject: [SOLVED] javascript behavior to redirect |
|
|
Hi,
In the HTML sample code below, buttons 3 and 4 behave consistently throughout several browser versions.
However, buttons 1 and 2 only work with IE 11 or less (at least, that's what I tried). Definition of "work": the browser opens the Gentoo site within the same frame.
On the other hand, the latest Firefox and Edge do NOT work. They open the form's action page (ie. testme.php).
Code: |
<HTML>
<BODY>
<form method="post" action="testme.php">
<BUTTON onclick="window.location.href='https://www.gentoo.org';">Button 1</BUTTON>
<BUTTON onclick="window.open('https://www.gentoo.org', '_self');">Button 2</BUTTON>
</form>
<BUTTON onclick="window.location.href='https://www.gentoo.org'">Button 3</BUTTON>
<BUTTON onclick="window.open('https://www.gentoo.org', '_self')">Button 4</BUTTON>
</BODY>
</HTML>
|
Why does the above not work the same on all browsers?
I require having buttons within a FORM that point to different sites.
Any ideas?
Last edited by Vieri on Mon Feb 05, 2018 10:25 am; edited 3 times in total |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21642
|
Posted: Sat Feb 03, 2018 1:17 am Post subject: |
|
|
Rather than fake it with Javascript, why not do the right thing directly? Use the formaction attribute on the button to override the form action on a per-button basis. According to Mozilla Developer Network, this is supported on Chrome, Edge, Firefox, and IE >= 10. |
|
Back to top |
|
|
charles17 Advocate
Joined: 02 Mar 2008 Posts: 3664
|
Posted: Sat Feb 03, 2018 5:23 am Post subject: Re: javascript behavior to redirect |
|
|
Vieri wrote: | Hi,
In the HTML sample code below, buttons 3 and 4 behave consistently throughout several browser versions.
However, buttons 1 and 2 only work with IE 11 or less (at least, that's what I tried). Definition of "work": the browser opens the Gentoo site within the same frame.
On the other hand, the latest Firefox and Edge do NOT work. They open the form's action page (ie. testme.php).
Code: |
<HTML>
<BODY>
<form method="post" action="testme.php">
<BUTTON onclick="window.location.href='https://www.gentoo.org';">Button 1</BUTTON>
<BUTTON onclick="window.open('https://www.gentoo.org', '_self');">Button 2</BUTTON>
</form>
<BUTTON onclick="window.location.href='https://www.gentoo.org'">Button 3</BUTTON>
<BUTTON onclick="window.open('https://www.gentoo.org', '_self')">Button 4</BUTTON>
</BODY>
</HTML>
|
Why does the above not work the same on all browsers?
I require having buttons within a FORM that point to different sites.
Any ideas? |
Newer browsers are more standards compliant. Older I.E. never was.
Drop your code here and let it tell you what's wrong: http://validator.w3.org/#validate_by_input |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21642
|
Posted: Sat Feb 03, 2018 6:08 pm Post subject: |
|
|
If you need more advice, please list the supported browsers and versions. Ranges are fine, but we need to understand the minimum supported version for each browser. It's fairly common to drop support for non-recent Chrome/Firefox, but it's also somewhat common for people to insist on support for ancient versions of Internet Explorer. Similarly, some sites may completely ignore mobile browsers, Apple Safari, Opera, etc. Others may insist on supporting everything. Correct advice depends on knowing which browsers can be safely excluded. |
|
Back to top |
|
|
Vieri l33t
Joined: 18 Dec 2005 Posts: 882
|
Posted: Sat Feb 03, 2018 10:57 pm Post subject: |
|
|
sounds great. All I really need to support is recent Firefox versions (also Edge, eventually).
Thanks to all. |
|
Back to top |
|
|
Vieri l33t
Joined: 18 Dec 2005 Posts: 882
|
Posted: Mon Feb 05, 2018 10:24 am Post subject: |
|
|
Just wanted to point out that one might need to use formmethod in conjunction with formaction. In my case, I needed to use formmethod="get".
Thanks |
|
Back to top |
|
|
|