Menu

#277 Are you sure you want to leave page?

open
None
5
2013-09-04
2013-03-18
Lee Worden
No

It's nice that it asks this when you click away from a page you're editing. Not so much when you click to open a pdf file from a preview page.

Related

Bugs: #321
Bugs: #425

Discussion

  • Lee Worden

    Lee Worden - 2013-07-26

    "Watch this page" is a MW link that doesn't trigger this warning. Find out how they do it and do the same.

     
  • Lee Worden

    Lee Worden - 2013-07-26

    It only warns when previewing, not on the initial edit page, for some reason

     
    • Lee Worden

      Lee Worden - 2013-07-26

      It also warns on the initial edit page in MW 1.22alpha

       
  • Lee Worden

    Lee Worden - 2013-07-26

    It's in ext.Vector.editWarning.js, a function that's called at window.onbeforeunload. I don't understand why/how Watch/Unwatch escapes triggering this event. The link looks the same as other links.

     
    • Lee Worden

      Lee Worden - 2013-07-26

      The watch link is given a click event handler in mediawiki.action.watch.js, which performs an Ajax call to do the watch/unwatch action and uses preventDefault() and stopPropagation() to stop the browser from actually navigating to the link's target.

      This is a bit different from what I want to do with links like [pdf] and display=download files, which is to simply go ahead to the link's target because I know it won't actually leave the page. I guess the best way to handle those is either to write an onbeforeunload handler to modify the behavior of the other one if a download link is being clicked (somehow), or put a click handler on the download links that suppresses Vector's onbeforeunload. I think I like the second option as more straightforward. Just remove the handler and let the click proceed.

       
  • Lee Worden

    Lee Worden - 2013-07-26

    Now that I've got this mostly written, the problem is that it isn't safe. display=download can take you to another page, if the file can't be made or retrieved. I would have to do something more sophisticated to make sure the file's coming before letting go of the current page. Can I do a display=raw call by Ajax and let the file get downloaded if it comes with a success code?

     
    • Lee Worden

      Lee Worden - 2013-07-26

      Maybe just put it in an invisible iframe and do something appropriate if there's an error?

       
    • Lee Worden

      Lee Worden - 2013-07-26

      maybe best leave this for now...

       
  • Lee Worden

    Lee Worden - 2013-07-26
    • status: open --> closed
     
  • Lee Worden

    Lee Worden - 2013-07-26

    OK there are surely better uses for my time but I got it working: load the URL into a hidden iframe, use the load() event to catch failures and pop up a dialog. Had to hack the URL from display=download to display=raw, because download generates a MediaWiki page with error message somewhere within - which would be fine except that MW generates an X-Frame-Options header saying you can't embed it in an iframe!

    Anyway there it is, if it succeeds you get to save or open the file, and if it fails you get a dialog saying it failed... if there's more specific error info you don't get it, you have to click to open the download link in another tab to see what the messages are. Not 100% sure whether this is better than just leaving the download link with the "leave this page" popup, but right now I think I could live with either...

    Eventually I could either rewrite this to use the get-project-file API, or change display=raw (or a variant of it) to return all the error messages. That latter sounds like a good, simple idea, honestly.

     
  • Lee Worden

    Lee Worden - 2013-07-26

    Ha! Got the actual messages in the dialog now, with display=raw. Also am no longer altering the links' targets in place, so you still get display=download if you open the link in another tab.

     
  • Lee Worden

    Lee Worden - 2013-09-04
    • status: closed --> open
     
  • Lee Worden

    Lee Worden - 2013-09-04

    Just clicked on a project-file link while previewing in my wiki (MW 1.19) and got the "Leave this page" popup. Why? The link is just this tag:

    <project-file filename="handout-primes.pdf"/>
    
     

Anonymous
Anonymous

Add attachments
Cancel