Javascript window.open question

Questions and information about creating Internet aware NeoBook applications. Including PHP, HTML, FTP, HTTP, Email, etc.

Moderator: Neosoft Support

Locked
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Javascript window.open question

Post by fkapnist »

The following Javascript opens Internet Explorer in a popup window
win = window.open('about:blank','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=300');
win.document.open("text/html","replace");
win.document.writeln("<HTML><HEAD><TITLE>My Test Page</TITLE>");
win.document.writeln("</HEAD>");
win.document.writeln("<BODY BGCOLOR=FFFFFF>");
win.document.writeln("<FONT face=Tahoma size=2 color=000000>");
I don't want to use a popup. How do I open Internet Explorer in RunInRectangle / CustomWindow? Or how do I send the JS "document.writIn" code to a Neobook WebBrowser object? In that case, what should "win=window.open" be replaced with?

:?:
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Javascript window.open question

Post by Gaev »

fkapnist:
How do I open Internet Explorer in RunInRectangle / CustomWindow?
The CustomWindow command syntax is ...

Code: Select all

CustomWindow "title" "left" "top" "object name" "options"
From the Help file ...
The Container object is primarily intended to be used as a surface for other objects. It’s similar to a group, except that objects placed on a container can be moved and edited easily. This makes the Container an excellent tool for creating sizeable publications and custom windows.

To add a Container to your publication, use the mouse to draw a rectangle where you would like the object to appear. Other objects can be attached to a Container by selecting a tool from the Tool Palette and drawing directly onto the Container’s surface. (You can even attach other Containers.) Existing objects can be moved onto a Container by cutting and pasting them from the clipboard. When using this method, make sure that the container is selected before choosing paste. To move an object off a container, select the object, cut it to the clipboard, make sure no other objects are selected, then paste. Once an object is attached to a Container, the two become linked. Moving the Container also moves any attached objects. Similarly, deleting a Container also deletes any attached objects.

You can modify a Container by right clicking the object. The Container Properties screen will be displayed, allowing you to define the object’s appearance and behavior.
... so at Design time, you can place a Rectangle outside your visible pub window ... and populate it with a WebBrowser object ... and at Run time, you can invoke the CustomWindow command with appropriate/desired parameter values.

Also from the Help file ...
You can define special subroutines that will be executed when a specific custom window is opened or closed. To do this, simply create two subroutines - one called ObjectName_OnOpen and one called ObjectName_OnClose. Replace ObjectName with the name of object used when opening the window. For example, the subroutines for our Container1 sample above might look like this:

:Container1_OnOpen
AlertBox "Hello" "The window is opening."
Return
:Container1_OnClose
AlertBox "Hello" "The window is closing."
Return
... so you might consider using such subroutines to populate the contents of the WebBrowser object in the CustomWindow ... take a look at the BrowserLoadFromStr command for this.
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: Javascript window.open question

Post by fkapnist »

This is a javascript that runs a Neobook Action... so what should "win=window.open" be replaced with?
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Javascript window.open question

Post by Gaev »

fkapnist:
This is a javascript that runs a Neobook Action... so what should "win=window.open" be replaced with?
The javascript pops up a new (IE) window and loads the following content within it ...

Code: Select all

"<HTML><HEAD><TITLE>My Test Page</TITLE></HEAD><BODY BGCOLOR=FFFFFF><FONT face=Tahoma size=2 color=000000></BODY></HTML>"
The suggested solution is to use CustomWindow as the (simulated) popup window.

Say the WebBrowser object in the Container is called WebBrowser6 ... then your command ...

Code: Select all

BrowserLoadFromStr "WebBrowser6" "<HTML><HEAD><TITLE>My Test Page</TITLE></HEAD><BODY BGCOLOR=FFFFFF><FONT face=Tahoma size=2 color=000000></BODY></HTML>"
... will populate the WebBrowser object with this content.

And if the Container object that hosts the WebBrowser object is called Container3, then this subroutine ...

Code: Select all

:Container3_OnOpen
BrowserLoadFromStr "WebBrowser6" "<HTML><HEAD><TITLE>My Test Page</TITLE></HEAD><BODY BGCOLOR=FFFFFF><FONT face=Tahoma size=2 color=000000></BODY></HTML>"
Return
... will make sure that the desired HTML is loaded each time you invoke the CustomWindow command in your pub.
Or how do I send the JS "document.writIn" code to a Neobook WebBrowser object? In that case, what should "win=window.open" be replaced with?
If all you want to do is have this HTML run in a WebBrowser object (on some page of your pub), just invoke the ...

Code: Select all

BrowserLoadFromStr "WebBrowser6" "<HTML><HEAD><TITLE>My Test Page</TITLE></HEAD><BODY BGCOLOR=FFFFFF><FONT face=Tahoma size=2 color=000000></BODY></HTML>"
... command somewhere on that page (e.g. PageEnter event section or Click of a Button etc.).
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: Javascript window.open question

Post by Tony Kroos »

I think he may need something different...
This is a javascript that runs a Neobook Action... so what should "win=window.open" be replaced with?
Why don't you explain what you want to achieve, so we don't need to speculate? What javascript? Where and how it runs? Maybe the question is "how to run Neobook action from javascript?" etc...
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Javascript window.open question

Post by Gaev »

fkapnist:
Why don't you explain what you want to achieve, so we don't need to speculate? What javascript? Where and how it runs? Maybe the question is "how to run Neobook action from javascript?" etc...
... +1 :D
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: Javascript window.open question

Post by fkapnist »

Tony Kroos wrote:I think he may need something different...
This is a javascript that runs a Neobook Action... so what should "win=window.open" be replaced with?
Why don't you explain what you want to achieve, so we don't need to speculate? What javascript? Where and how it runs? Maybe the question is "how to run Neobook action from javascript?" etc...
OK... Here is a snippet of javascript that creates a RSS reader on the fly and opens it in a new browser window:

Code: Select all

            var link = document.createElement('a');
            link.setAttribute('href', entries[i].link);
            link.setAttribute('target','_blank');
            var text = document.createTextNode(title);
            link.appendChild(text);
Notice link . setAttribute ('target','_blank');

I want to change "_blank" to WebBrowser1. But I can't get the right javascript syntax for it... Most of that script comes from a Google API so I can't use another function or change it much
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Javascript window.open question

Post by Gaev »

fkapnist:

Sorry, your response does NOT help much but ...
I want to change "_blank" to WebBrowser1. But I can't get the right javascript syntax for it.
... if the document containing the link is hosted in the same WebBrowser1 object, then ...

a) the short answer is ...

Code: Select all

link.setAttribute('target','_self');
b) you can invoke javascript on the current document in a WebBrowser object using ...

Code: Select all

BrowserExecScript "WebBrowser1" "[yourScriptGoesHere]" "JavaScript"
... see the Help file for details.
Locked