tags:

views:

241

answers:

3

There is one form i have and a user can click on preview button or save button , both buttons send data to different locations.

Here is the relevant code:

prevAction = location.href;
document.getElementById('preview').value='true';
document.getElementById('form1').target='_blank';
document.getElementById('form1').action = 'http://www.xxx.com/do/preview';
document.getElementById('form1').submit();
document.getElementById('form1').target='';
document.getElementById('preview').value='';
document.getElementById('form1').action = prevAction;

Now it works fine with 99.9% users , however only 2 users have complained so far that it doesn't work for them. One of them is using mac and says it doesnt work in safari and firefox both. When he hits preview , the form data doesn't seem to be post and after hitting preview if they hit save , the form data doesnt go thru as well.Can you guys tell me what i am doing wrong here.

Also one thing which might be relevant .. i mootools is loaded in the head section but this piece of code doesnt make use of it.. can this have an effect?

A: 

Just in case there's a hidden error in that user's environment, you could add an onerror handler that catches errors and logs them via AJAX to find out. See this question for sample code.

This isn't supported by Safari, but supported by Firefox.

orip
this might be the last resort i will have to goto
Sabeen Malik
A: 

This could be related to these Chrome and Safari bugs where FORM with target="_blank" does not always work as expected.

kangax
thats the interesting bit here.. it doesnt work with Safari and Firefox on MAC. and the other user says it gives him blank page on clicking preview in IE8 .. interestingly all of them report that the new window/tab does open .. so _blank seems to work ok.
Sabeen Malik
But the ticket mentions that form is **only submitted once**. Could that be the problem?
kangax
nah .. u can click on preview and that would open a new window and then once ur satisfied with how ur content looks after several previews u can click save
Sabeen Malik
+1  A: 

If submit url and preview url are both in same javascript security sandbox. Then in case of preview: instead of submiting a form, you can just open a new window. And then access data from this window, in a new window, to show your preview.

EDIT

Your real problem is that browser is not accepting 'target' attribute for 'form' tag. It is a deprecated attribute. Which is only available in TF (Transitional & Frameset) DTD. But it is not available in Strict DTD.

You can do things: Change your DTD to TF and hope for the best.

OR: You can implement the above stated solution.

Krishna Kant Sharma
yeah thats a solution too .. but i want to know why the above isnt working as it should
Sabeen Malik
Thank you i think i will go with what you say and hope for the best :)
Sabeen Malik