Location: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 37: Line 37:
== Example ==
== Example ==


<pre>
<tabber>
JavaScript=
<syntaxhighlight lang="JavaScript">
// Location Example
NSB.MsgBox("The name of this app is " + location);
NSB.MsgBox("Going to http://www.nsbasic.com/Project1/index.html?someParameters");
location = "http://www.nsbasic.com/Project1/index.html?someParameters";
 
// PROJECT1
NSB.MsgBox("Started with parameter " & location.search);
</syntaxhighlight>
|-|
BASIC=
Rem Location Example
Rem Location Example
MsgBox "The name of this app is " & location
MsgBox "The name of this app is " & location
MsgBox "Going to http://www.nsbasic.com/Project1/index.html?someParameters"
MsgBox "Going to http://www.nsbasic.com/Project1/index.html?someParameters"
location = "http://www.nsbasic.com/Project1/index.html?someParameters"
location = "http://www.nsbasic.com/Project1/index.html?someParameters"
 
Rem PROJECT1
Rem PROJECT1
MsgBox "Started with parameter " & location.search
MsgBox "Started with parameter " & location.search
</pre>
</syntaxhighlight>
</tabber>


Send your own query string (instead of [[Form]] Submit())
Send your own query string (instead of [[Form]] Submit())
<pre>
<pre>
location="http://someurl.com/index.html?parameter1=one&parameter2=two"
location.href="http://someurl.com/index.html?parameter1=one&parameter2=two"
</pre>
</pre>


Open a web page:
Open a web page:
<pre>
<pre>
location = "http://news.google.com"
location.href = "http://news.google.com"
</pre>
 
Open the Phone app:
<pre>
document.location.href = "tel:+1-800-555-1234"
</pre>
 
Read the query string which was passed to your app
<pre>
queryParams = location.search
</pre>
</pre>



Latest revision as of 13:46, 25 November 2019

Location[(string | variable)]

Description

Location lets you get or set the name of the current app. It will return the URL of the current app that you are running. If you want to run another app or go to a web page, assign the URL of that app to Location. In this respect, it works similarly to the Chain statement found in some other implementations of BASIC.

To send parameters to the next app, put a question mark (?) followed by the string after the new app name.

Properties and Methods

hash Sets or returns the anchor part (#) of a URL
host Sets or returns the hostname and port number of a URL
hostname Sets or returns the hostname of a URL
href Sets or returns the entire URL
origin Returns the protocol, hostname and port number of a URL
pathname Sets or returns the path name of a URL
port Sets or returns the port number of a URL
protocol Sets or returns the protocol of a URL
search Sets or returns the querystring part of a URL
assign() Loads a new document
reload() Reloads the current document
replace() Replaces the current document with a new one

Example

// Location Example
NSB.MsgBox("The name of this app is " + location);
NSB.MsgBox("Going to http://www.nsbasic.com/Project1/index.html?someParameters");
location = "http://www.nsbasic.com/Project1/index.html?someParameters";

// PROJECT1
NSB.MsgBox("Started with parameter " & location.search);

Send your own query string (instead of Form Submit())

location.href="http://someurl.com/index.html?parameter1=one&parameter2=two"

Open a web page:

location.href = "http://news.google.com"

Open the Phone app:

document.location.href = "tel:+1-800-555-1234"

Read the query string which was passed to your app

queryParams = location.search

Output

?someParameters