I'm trying to open a URL on my Raspberry PI using C++ or C. Using the command system("xdg-open http://something.com); the default browser opens the first time, but on every next try a new tab opens. I would like to check, if the browser is open, then open the desired url in the existing tab. There is nothing more to it: no posting of any forms, or reading data from the site. How could I achieve this in C++ and C?
Thanks in advance,
Alexander
When using system() you should configure your default browser, so that it opens all external URLs in the current active tab. For instance with Firefox type in the addres bar about:config and search for files begining with browser.link.open_. To answer the question, you should configure the files accordingly:
browser.link.open_external value = 1
browser.link.open_newwindow value = 1
browser.link.open_newwindow.override.external value = 1
browser.link.open_newwindow.restiction value = 0
The above will make sure, that all URLs get open in the same tab, no matter how many times your code repeats itself.
Make sure to open Firefox in advance, otherwise the code will stop running as soon as Firefox opens.
Related
I wrote a Qt widget application. In the file menu I want to insert an MS word document as a user manual. Is there any way to do it? I checked Qt help and various blogs but none of them gave me a clear solution.
If it is only manual then it is not necessary to embed MS Word inside your app. Maybe try to open needed document with Word installed in computer. Try this code:
QDesktopServices::openUrl(QUrl("file:///G:/tst.docx"));
Just set needed path. As doc said:
If the URL is a reference to a local file (i.e., the URL scheme is
"file") then it will be opened with a suitable application instead of
a Web browser.
If you want to embed it in your application executable, just insert your .docx file as a resource file. To open the docx file from resources, you should first copy it to some location for example in the application directory path :
QFile HelpFile("qrc:/myFile.docx");;
HelpFile.copy(qApp->applicationDirPath().append("/myFile.docx"));
Next you can open it by :
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath().append("/myFile.docx")));
I'm using Webstorm for my phaser game development. It's been ok up till now but now I'm a tad confused as to how I've got things set up.
I've got a project called say myGame1, and when I run the index page it opens up like this in the browser
http://localhost:63342/myGame1/index.html
And that runs fine.
What I can't seem to figure out is how to set things up so I can have another game project open as well, and open that games index page as well in the browser. Because when I try to do that, it just opens the previous game still.
I think it's got something to do with configurations, I've tried to set up another one but when I try to use that config it just says error 404 when opening in a browser.
Any ideas?
I am trying to open a local html document using Shell Execute(). But, what i need is, Suppose if that particular document is already opened and if ShellExecute is triggered again, then that particular file should not be opened again instead bring the already opened file into foreground. Can you please suggest how can i do this?
void main()
{
ShellExecute(NULL, "open", "C:\\prograomgiles\\help.html",
NULL, NULL, SW_SHOWNORMAL);
}
It's nearly impossible, because it depends on which program processes the html files and how does it work. Suppose, that my OS opens html files by printing them directly on a printer. How would you bring opened file into foreground?
If you want to display HTML content in the way specified by you, write your own browser (It's quite easy, you can - for example - embed IE in C#.NET application) and run it instead of default system browser. You would have then full control on how your files are displayed.
Many web browsers respond to DDE messages, particularly the WWW_OpenURL message. Not sure about other browsers, but IE also responds to WWW_GetWindowInfo and WWW_Activate messages, which you could use to enumerate open windows and their URLs, and then activate a particular window.
I am trying to build an install CD with a custom MFC application set to autorun when the CD is inserted.
The instructions are included as a simple html page with images and links to PDF documents, all of which are located on the CD.
In the past I'd used the following to open the html page with the default browser:
ShellExecute(NULL, "open", <full path to .htm file including CD drive letter>, NULL, NULL, SHOWNORMAL);
But when testing with IE8 under vista I've encountered the following:
Explorer launches
The tab says 'Connecting'
Explorer dissappears
This has to do with protected mode, since if you turn off protected mode for the internet zone, the problem goes away.
The strange thing is that the problem only shows up once everthing is burned onto a CD. If I just run the autorun executable manually from my hard drive, the html page comes up just fine.
So I'm asking if there is anything specific I can do to fix this?
Or if there is another mechanism for opening URLs with the user's default browser that might not have this problem?
Since you can be reasonably sure that IE is installed you might want to execute
iexplore.exe [URL]
in your shellex call.
In case IE is not installed, check the return value to see if it isn't not found. If so do your original shellex call directly on the .htm file.
Alternatively, You can copy the .htm to a %TEMP%, and run the shellex call from there. That way it gets around the protected aceess from a "risky" location.
Can you capture and display the return code from the ShellExecute? That might give us a clue as to what is happening.
result = ShellExecute(...
Possible return codes are listed here:
http://support.microsoft.com/kb/238245
It says in your question that you are hard-coding the CD-ROM drive letter. Does the machine you are testing on have a different drive letter than the one you created the CD on?
I have a situation that has been partially covered by other answers at SO, but I cannot find a complete answer. In short, we are trying to use URL's for our specific data types that when double clicked will open up our application and load those data sets into that app. We have this part working.
(for example, an URL might look like this: resource://shaders/basic_shader.hlsl)
What we would like to do is to prevent new instances of the application from opening when a new URL is double clicked. For example, let's say we have a URL that opens up a shader in our shader editor. When clicking this resource URL, it will open our shader editor. When a new shader URL is clicked, we'd like to be able to open up the shader in the currently running application and have it open up the new shader in a new tab in our editor.
We can easily detect if another instance of our application is running. The problem that we don't know how to easily solve is how to tell the currently running application to open up this new file for editing. This behavior is very much like the Apple Finder.
In unix, you could emulate this behavior by having your application open some named pipe and then new apps could check if this pipe is active and then send the document data down the pipe. Is there a more standard windows way of achieving this behavior?
We need a C/C++ solution. Thanks.
Named pipe is the best way.
First instance of your application opens the pipe and listens to it (use PIPE_ACCESS_INBOUND as dwOpenMode and the same code will also allow you to detect running instances).
All subsequent instances check that they are not alone, send command line argument to the pipe and shut down.
Create a named mutex when application launches as David Grant said, then before displaying the UI for the second URL, check for this mutex, if it is already created then just quit by passing the new URL to the first launched application (Have interface in the application to set the URL and tell to redirect programatically)
You can't avoid the program associated with the url to be executed.
The "windows" solutions would be to send a message (via DDE in the old days but maybe there is something more "modern" now) to the previously running application with the url then quit ...
You can acquire a named mutex upon startup and enforce it that way.
http://www.google.com/search?hl=en&q=named+mutex+single+instance
CreateMutex on MSDN
I got this working pretty well for my C++ MFC application by following Joseph Newcomer's tutorial here. He uses a named mutex that is checked on startup and a message sent to the already-running application with the new resource to be opened.