Sachin
Sachin

Reputation: 3782

Open redirect page in new tab and reopen in the same tab on multiple redirects Django

I am making a blog app in Django and I want to do the following things

  1. When the user submits the preview button I want to open the partially completed blog in a new tab in the same window.
  2. Secondly if the user does not close the tab and again presses preview button, I want to display the updated blog in the tab which was previously opened.

How can I do this?

Edit: As told in the answer below I am trying to use this code snippet to open it in a new window, but this does not work

<script>
    var current_link = $(location).attr('href');
    $('.preview_button').onClick(function() {
        window.open(current_link,'preview_tab');
    });
</script>

Also I currently have 3 submit buttons and I want to provide this feature only for 1 submit button i.e. preview So I cannot directly do (#form).onSubmit. For the the other two buttons, one updates the content via Ajax and the other redirects to a new page.

Upvotes: 1

Views: 4991

Answers (1)

Danica
Danica

Reputation: 28846

Try using a Javascript onSubmit to open the appropriate preview page with window.open, passing a name as the second parameter. It does almost exactly that. (If you want to support having different preview tabs associated with different editing tabs, include something in the name based on a tab ID of some kind -- maybe the article ID plus a random number, or something.)

You'll have to also send the updated content into the server via AJAX.

Upvotes: 2

Related Questions