Using JavaScript in RS Navigation

  • Greetings,

    I've placed some JavaScript in the "jump to URL" navigation property of an RS report:

    " target="contents";

    onmouseout=" win.window.close(); return true;"; onmouseover="win = window.open('http://edinburgh/Employee Photos/Joe-Jones.jpg','','width=250,height=250,left=380,top=150');return true;";"

    The idea behind adding the script is for RS to generate a department phone listing, with a link next to each employee's name that pops up the employee's photo when moused over, and disappears the photo when moused out.  (The employee name, eg, "Joe-Jones", will  be dynamically supplied, BTW, once the following issue gets solved...)

    The JavaScript works fine when I embed it in a test stand-alone webpage, so the script is "known-good".  The script looks fine in the .rdl file as well:

    <Action>

    <Hyperlink>" target="contents"; onmouseout=" win.window.close(); return true;"; onmouseover="win = window.open('http://edinburgh/Employee Photos/Joe-Jones.jpg','','width=250,height=250,left=380,top=150');return true;";"</Hyperlink>

    </Action>

    (I've discovered you don't need to supply the initial "=".)

    However, in Report Manager, the JavaScript is rendered as:

    "%20target=%22contents%22;%20onmouseout=%22%20win.window.close();%20%20return%20true;%22;%20onmouseover=%22win%20=%20window.open('http://edinburgh/Employee%20Photos/Joe-Jones.jpg','','width=250,height=250,left=380,top=150');return%20true;%22;"

    and of course no longer works (at least, not as intended!).  RS assumes, apparently, that only URLs will ever be placed in to the "jump to URL" property, in which case hex escape sequencing is not only acceptable, but desireable as well.  But it's no good if you're trying to push the limits a little and use some JavaScript instead!

    BTW, some JavaScript works in this context, but only so long as the hex escape sequences are enclosed within a string, eg:

    " alert('Red%20Alert');"

    Would any one happen to have a way to prevent the report renderer throwing in the hex escape sequences and ruining my JavaScript, please?  Many thanks!

    Craig

  • I have never tried to embed javascript in the jump to URL in reporting services, but you might want to try putting a custom function in the Jump to URL that returns the javascript.   Something like:

    Public Function GenerateJavaScript(EmpName as String) as String

       Dim strJava as String = " target=""contents""; onmouseout="" win.window.close(); return true;"";"

       strJava = strJave & "onmouseover=""win = window.open('http://edinburgh/Employee Photos/" & _

       EmpName & ".jpg','','width=250,height=250,left=380,top=150');return true;"";"

      

       Return strJava

    End Function

  • Hi, Jack,

    Thanks for responding to my distress call!  I tried out your idea - I placed the public function in the report "code-behind", and called it from the "Jump to URL" property like this:

    =Code.GenerateJavaScript("Joe-Jones")

    It "works", in a way: the function call does it job, as does the public function itself.  But the report renderer, at run time, still substitutes hex escape sequences for "special characters": "%20" for whitespace, and so on.  The results are exactly what I had encountered on my first try.  (Well, at least it's all consistent!)

    The real problem is, I think, preventing the report renderer at *run time* from reading the JavaScript, thinking it's a URL, and performing its hex escape sequence substitution parsing action.  I just don't know how to "turn it off".

    But it was worth a try!  Thanks again.

    Craig

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply