Open link in new browser window: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
|||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|techtonik}} | |||
== Description == | == Description == | ||
Link opened via '''ExecShell "open" "http://nsis.sf.net/"''' may happen to be loaded in existing browser window thus erasing previous content. Here is NSIS function to open link in new window. | Link opened via '''ExecShell "open" "http://nsis.sf.net/"''' may happen to be loaded in existing browser window thus erasing previous content. Here is NSIS function to open link in new window. | ||
Update by qwertymodo | |||
Use the new version with the included macro to execute without affecting any variables or the stack :) | |||
== The Function == | == The Function == | ||
<highlight-nsis> | <highlight-nsis> | ||
Function openLinkNewWindow | Function openLinkNewWindow | ||
Push $3 | Push $3 | ||
Exch | |||
Push $2 | Push $2 | ||
Exch | |||
Push $1 | Push $1 | ||
Exch | |||
Push $0 | Push $0 | ||
Exch | |||
ReadRegStr $0 HKCR "http\shell\open\command" "" | ReadRegStr $0 HKCR "http\shell\open\command" "" | ||
# Get browser path | # Get browser path | ||
Line 32: | Line 42: | ||
Pop $0 | Pop $0 | ||
Exec '$1 $0' | Exec '$1 $0' | ||
Pop $0 | |||
Pop $1 | Pop $1 | ||
Pop $2 | Pop $2 | ||
Pop $3 | Pop $3 | ||
FunctionEnd | FunctionEnd | ||
!macro _OpenURL URL | |||
Push "${URL}" | |||
Call openLinkNewWindow | |||
!macroend | |||
!define OpenURL '!insertmacro "_OpenURL"' | |||
</highlight-nsis> | |||
And you call it like this: | |||
<highlight-nsis> | |||
${OpenURL} "www.google.com" | |||
</highlight-nsis> | |||
You can also call it with a file parameter like this: | |||
<highlight-nsis> | |||
${OpenURL} "c:\mywebsite\index.html" | |||
</highlight-nsis> | </highlight-nsis> | ||
Thanks to Ryan Farley (http://ryanfarley.com/blog/archive/2004/05/16/649.aspx ) for an idea. | Thanks to Ryan Farley (http://ryanfarley.com/blog/archive/2004/05/16/649.aspx ) for an idea. | ||
[[Category:Internet Functions]] |
Latest revision as of 14:58, 14 June 2010
Author: techtonik (talk, contrib) |
Description
Link opened via ExecShell "open" "http://nsis.sf.net/" may happen to be loaded in existing browser window thus erasing previous content. Here is NSIS function to open link in new window.
Update by qwertymodo Use the new version with the included macro to execute without affecting any variables or the stack :)
The Function
Function openLinkNewWindow Push $3 Exch Push $2 Exch Push $1 Exch Push $0 Exch ReadRegStr $0 HKCR "http\shell\open\command" "" # Get browser path DetailPrint $0 StrCpy $2 '"' StrCpy $1 $0 1 StrCmp $1 $2 +2 # if path is not enclosed in " look for space as final char StrCpy $2 ' ' StrCpy $3 1 loop: StrCpy $1 $0 1 $3 DetailPrint $1 StrCmp $1 $2 found StrCmp $1 "" found IntOp $3 $3 + 1 Goto loop found: StrCpy $1 $0 $3 StrCmp $2 " " +2 StrCpy $1 '$1"' Pop $0 Exec '$1 $0' Pop $0 Pop $1 Pop $2 Pop $3 FunctionEnd !macro _OpenURL URL Push "${URL}" Call openLinkNewWindow !macroend !define OpenURL '!insertmacro "_OpenURL"'
And you call it like this:
${OpenURL} "www.google.com"
You can also call it with a file parameter like this:
${OpenURL} "c:\mywebsite\index.html"
Thanks to Ryan Farley (http://ryanfarley.com/blog/archive/2004/05/16/649.aspx ) for an idea.