Ok, hands up – I’ve only recently realised that the URL parameters functionality in Visio Save As Web output work on straight .html pages and not just server based platforms such as ASP.NET.
I’d tried this some time ago on a local machine (using the file:// URL schema) and had assumed, incorrectly, that as URL parameters weren’t recognised that this would be the same when hosted (via http://). This is not the case and so I thought I’d try and set the record straight by reviewing how to use this handy part of the Save As Web addon…
What are URL parameters?
URL parameters allow you to append the standard page URL with settings that are evaluated as the page loads. Basic use of a query string is to add a ‘?’ character to the end of the URL followed by a number of key/value pairs, which are in turn separated by an ampersand.
http://www.domain.com/VisDiagram.htm?page=Page-1&zoom=200
Visio parameters
Visio Save As Web output includes four parameters to control a number of aspect of the page as it loads. These are as follows:
- page=PageName – allows you to link to a specific page by name. The page name is case insensitive and spaces should be replaced by ‘%20’. (Note – you cannot link to a page index, but see below if this is something you need to do.)
- shape=ShapeName – allows you to link to a specific shape by name. To link to a shape you must specify the page name as above.
- zoom=ZoomLevel – sets the opening zoom to a figure between 10 and 500%. If you try and set a level outside of this range the default zoom of 100% will be set.
- search=SearchWord – opens the page with search results displayed. There’s no way to specify the search criteria within the parameter as you can through the UI, so all fields (name, text and data) are searched.
This is all covered in this link: About saving drawings as Web pages (apart from the ‘shape’ parameter), so I’m not sure why I didn’t come across it before. If you read my post on Linking to a specific page in Save As Web you are no doubt thinking of sledgehammers and nuts right now and I think I’d agree with you. Well you live and learn…
Extending URL parameters with code
While you get the above four parameters as standard there maybe situations where you want to extend the existing functionality with parameters of your own. For example, suppose you want to add the ability to link to a page by index rather than by name, you could add a short bit of JavaScript to deal with the following key/value pair:
- pageIdx=PageNumber – to allow you to link to a page by index. This will be a 1-based index (ie the first page will be index 1) and will override any page name parameter.
Walkthrough
- Open the main .htm page that Visio generates in a text editor, such as Notepad, and search for var g_FirstPageToLoad
- Just above this line insert the following code (download code as text) and then save and close the file.