NetTalk Central

Author Topic: JavaScript for every page  (Read 4078 times)

BColladay

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
JavaScript for every page
« on: November 10, 2010, 09:08:48 AM »
I have a javascript that I works in HTML files through this standard implementation:

<head>
<script language="javascript" type="text/javascript">
<!--
function initScreen()
{
setTimeout("window.scrollTo(0,1);",100);
}

function updateOrientation()
{
initScreen();
}
// -->
</script>
</head>

I saved the functions as a .js file (minus the html markup) and included them in the webserver custom script section.  It shows up in the source as:

<script src="/scripts/rotate.js" type="text/javascript"></script>

My question is:  How do I get this InitScreen() to fire when each page opens?

My JavaScript experience is limited to stealing and pasting from examples on the interwebs and copying their implementation.



BColladay

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: JavaScript for every page
« Reply #1 on: November 10, 2010, 03:06:23 PM »
I tried this(in red) here:

p_web.ProcessLink PROCEDURE(<string p_action>)

! Start of "NetTalk Method Data Section"
! [Priority 5000]

! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 1500]
 
  ! C5.5:  file{prop:name} = clip(self.site.appPath) & 'file.tps'
  ! [Priority 4000]
        self.MetaHeaders = '<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;"/>'
       
p_web.BodyOnLoad('setTimeout(function() { window.scrollTo(0, 1) }, 100);')

I get:
Invalid string (misused <...> or {...}, or literal is too long) - E:\source\PDS_Medical\PDSmobile\Source\PDSweb005.clw:531,26


kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: JavaScript for every page
« Reply #2 on: November 10, 2010, 07:27:11 PM »
Try to search for this embed

  ! Start of "After Form Inside Scripts"


you will also need this to add your script to the packet.

     packet = clip(packet) & ... ;


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: JavaScript for every page
« Reply #3 on: November 10, 2010, 11:01:08 PM »
first things first,
     
p_web.BodyOnLoad('setTimeout(function() { window.scrollTo(0, 1) }, 100);')
I get: Invalid string (misused <...> or {...}, or literal is too long)

The error is exactly right, in a clarion string the { character has a special meaning. (you can read up on that in the help if you like). The line of code should be
p_web.BodyOnLoad('setTimeout(function() {{ window.scrollTo(0, 1) }, 100);')
to compile correctly.

But wait, there's more.
Or more to the point, that's the wrong way to do what you want.

The right answer lies in the way JavaScript works. You've done the correct thing in creating rotate.js, and it contains the function, something like this I'm guessing;

function initScreen() {
setTimeout("window.scrollTo(0,1);",100);
}

function updateOrientation() {
initScreen();
}

Well, if you add the following line to the js file, at the bottom,

initScreen();

then when the js loads, that line will just run. IOW when the browser loads the js file, then it recognises the functions as, well, functions, and stores them for later use. But code outside functions (like the line at the bottom we just added) is executed - because it's not inside a function.

cheers
Bruce

BColladay

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: JavaScript for every page
« Reply #4 on: November 11, 2010, 06:26:47 AM »
Allright!  Yes, that worked! (of course it did.)

Thanks.