Question

I've wrote a simple 'add page' form to a small CMS I've built and I have a simple preview feature which submits a form and opens the front-end version of the page in a new window.

To achieve this up until now I've used:

<input type="submit" name="pagepreview" value="Preview" formtarget="_blank">

Apparently the formtarget which made this possible is depreciated (which I never actually knew) and it seems that Google may have removed this feature in their latest update as it's stopped working (but still works in Firefox).

What's my alternative here? The answers I've found all point back to formtarget or target but neither work any longer.

Ideally I'd want to avoid Javascript but if that isn't possible - how would I submit the form to a new window using Javascript or jQuery?

EDIT:

Apologies for not explaining well enough - I can't add the target attribute to the form as only one button allows a new window (the preview button) the others just submit on the same page. Javascript appears to be my only way to do this.

Was it helpful?

Solution

<form action="..." method="..." target="_blank">
   <input type="submit" name="pagepreview" value="Preview">
</form>

If you need to change the target dynamically:

 $('input[type="submit"]').click(function(event){
    var $this = $(this);
    var $form = $this.parents('form');
    $form.attr('target',$this.attr('formtarget'));
    $form.get(0).submit();
    event.preventDefault();
 });

OTHER TIPS

like this: (add target = "_blank")

<form action="" method="" target="_blank">
    <input type="text" />
</form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top