Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] javascript behavior to redirect
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Vieri
l33t
l33t


Joined: 18 Dec 2005
Posts: 882

PostPosted: Fri Feb 02, 2018 12:14 pm    Post subject: [SOLVED] javascript behavior to redirect Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21642

PostPosted: Sat Feb 03, 2018 1:17 am    Post subject: Reply with quote

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
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Sat Feb 03, 2018 5:23 am    Post subject: Re: javascript behavior to redirect Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21642

PostPosted: Sat Feb 03, 2018 6:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Vieri
l33t
l33t


Joined: 18 Dec 2005
Posts: 882

PostPosted: Sat Feb 03, 2018 10:57 pm    Post subject: Reply with quote

Code:
formaction
sounds great. All I really need to support is recent Firefox versions (also Edge, eventually).
Thanks to all.
Back to top
View user's profile Send private message
Vieri
l33t
l33t


Joined: 18 Dec 2005
Posts: 882

PostPosted: Mon Feb 05, 2018 10:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum