html - Javascript: inserting a variable as a parameter -
i looking @ getting "nodenumber" variable parameter of loadsynchpage function.
my code looks @ name of page (e.g. page.htm http://www.example.com/tree/page.htm) , after series of lines gives "nodenumber". page work out nodenumber , put function when page loads. i'd guess this:
<body onload="loadsynchpage(nodenumber);">
i have got code output nodenumber using button onlick. have got loadsynchpage(linkid) function, work using button onclick enter number myself. button , have got variable predefine work; can't read "nodenumber" , have spent 2 days trying figure out.
here code:
<script> function variables() { //getting page's name url pagename = location.pathname.split("/").slice(-1); document.getelementbyid("pagename").innerhtml = pagename; //converting page name string pagenamestring = string(pagename); document.getelementbyid("pagenamestring").innerhtml = pagenamestring; //converting string of page name, it's length pagelength = pagenamestring.length; document.getelementbyid("pagelength").innerhtml = pagelength; //setting demoframesetnodes.js variable (copy , paste in - needs have no " , on 1 line) textfromdemoframesetnodesjs = "folderstree = gfld(<i>page 1 title</i>, page1.htm)//000folderstree.treeid = framesetaux1 = insfld(folderstree, gfld(page 2 title, page 2.htm)) //001insdoc(aux1, glnk(r, page 3 title, page3.htm)) //002aux1 = insfld(folderstree, gfld(page 4 title, page4.htm)) //003insdoc(aux1, glnk(r, page 5 title, page5.htm)) //004"; //need set difference between "m" in htm , start of number //e.g. page2.htm)) //001 characterdifference = "5"; document.getelementbyid("characterdifference").innerhtml = characterdifference; //need find location of page's name demoframsetnodes pagenamelocation = textfromdemoframesetnodesjs.lastindexof(pagenamestring); document.getelementbyid("pagenamelocation").innerhtml = pagenamelocation; //need convert variables added numbers pagenamelocationnumber = number(pagenamelocation); pagelengthnumber = number(pagelength); characterdifferencenumber = number(characterdifference); document.getelementbyid("characterdifferencenumber").innerhtml = characterdifferencenumber; //add variables give start location of node number nodenumberstart = pagenamelocationnumber + pagelengthnumber + characterdifferencenumber; document.getelementbyid("nodenumberstart").innerhtml = nodenumberstart; //add variables give end location of node number nodenumberend = pagenamelocationnumber + pagelengthnumber + characterdifferencenumber + 3; document.getelementbyid("nodenumberend").innerhtml = nodenumberend; //this gives node number want nodenumber = textfromdemoframesetnodesjs.substring(nodenumberstart, nodenumberend); document.getelementbyid("nodenumber").innerhtml = nodenumber; } var avar=number(window.nodenumber); //window.nodenumber; function loadsynchpage(linkid) { var folderobj; docobj = parent.treeframe.findobj(linkid); docobj.forceopeningofancestorfolders(); parent.treeframe.hightlightnode(linkid,docobj.link,'basefrm'); if (typeof parent.treeframe.document.body != "undefined") // handle scrolling not working ns4 parent.treeframe.document.body.scrolltop=docobj.navobj.offsettop } //myvar=number(nodenumber); // function loadnode(){ // document.getelementbyid('loadsynchpage').onclick=function(){loadsynchpage(myvar);}; // var myvar=15; //function init(){ // document.getelementbyid('editbanner').onclick=function(){editbanner(myvar);}; // } </script> </head> <body> <button onclick="javascript:settingvariables();">page highlight1</button> <button onclick="javascript:loadsynchpage(avar);">page highlight2</button> page name: <p id="pagename"></p> page name string: <p id="pagenamestring"></p> page length: <p id="pagelength"></p> character difference: <p id="characterdifference"></p> page name location: <p id="pagenamelocation"></p> character difference number:<p id="characterdifferencenumber"></p> node number start: <p id="nodenumberstart"></p> node number end: <p id="nodenumberend"></p> node number: <p id="nodenumber"></p>
as can see "//" near bottom, have tried different ways other questions on stackoverflow - sure have tried , missing simple :/ have taken out "var" before setting things pagename , nodenumber after w3 said allow them become global variables?
to give more information:
the code based on treeview - has tree nodes on left , click on nodes open page in right hand frame. clicking on link page in right page different page doesn't update highlighting on node , why trying (onload).
edit: if possible code external .js , reference have multiple pages (i tried few hours last week different, working code, couldn't work either).
all need is:
window.onload = function() { loadsynchpage(nodenumber); };
or onload in body tag, problem have doesn't work in sandbox in snippet:
uncaught securityerror: sandbox access violation: blocked frame @ "http://stacksnippets.net" accessing frame @ "http://stackoverflow.com". frame requesting access sandboxed , lacks "allow-same-origin" flag.
function variables() { //getting page's name url pagename = location.pathname.split("/").slice(-1); document.getelementbyid("pagename").innerhtml = pagename; //converting page name string pagenamestring = string(pagename); document.getelementbyid("pagenamestring").innerhtml = pagenamestring; //converting string of page name, it's length pagelength = pagenamestring.length; document.getelementbyid("pagelength").innerhtml = pagelength; //setting demoframesetnodes.js variable (copy , paste in - needs have no " , on 1 line) textfromdemoframesetnodesjs = "folderstree = gfld(<i>page 1 title</i>, page1.htm)//000folderstree.treeid = framesetaux1 = insfld(folderstree, gfld(page 2 title, page 2.htm)) //001insdoc(aux1, glnk(r, page 3 title, page3.htm)) //002aux1 = insfld(folderstree, gfld(page 4 title, page4.htm)) //003insdoc(aux1, glnk(r, page 5 title, page5.htm)) //004"; //need set difference between "m" in htm , start of number //e.g. page2.htm)) //001 characterdifference = "5"; document.getelementbyid("characterdifference").innerhtml = characterdifference; //need find location of page's name demoframsetnodes pagenamelocation = textfromdemoframesetnodesjs.lastindexof(pagenamestring); document.getelementbyid("pagenamelocation").innerhtml = pagenamelocation; //need convert variables added numbers pagenamelocationnumber = number(pagenamelocation); pagelengthnumber = number(pagelength); characterdifferencenumber = number(characterdifference); document.getelementbyid("characterdifferencenumber").innerhtml = characterdifferencenumber; //add variables give start location of node number nodenumberstart = pagenamelocationnumber + pagelengthnumber + characterdifferencenumber; document.getelementbyid("nodenumberstart").innerhtml = nodenumberstart; //add variables give end location of node number nodenumberend = pagenamelocationnumber + pagelengthnumber + characterdifferencenumber + 3; document.getelementbyid("nodenumberend").innerhtml = nodenumberend; //this gives node number want nodenumber = textfromdemoframesetnodesjs.substring(nodenumberstart, nodenumberend); document.getelementbyid("nodenumber").innerhtml = nodenumber; } var avar=number(window.nodenumber); //window.nodenumber; function loadsynchpage(linkid) { alert("loadsynchpage called"); var folderobj; docobj = parent.treeframe.findobj(linkid); docobj.forceopeningofancestorfolders(); parent.treeframe.hightlightnode(linkid,docobj.link,'basefrm'); if (typeof parent.treeframe.document.body != "undefined") // handle scrolling not working ns4 parent.treeframe.document.body.scrolltop=docobj.navobj.offsettop } loadsynchpage(nodenumber); //myvar=number(nodenumber); // function loadnode(){ // document.getelementbyid('loadsynchpage').onclick=function(){loadsynchpage(myvar);}; // var myvar=15; //function init(){ // document.getelementbyid('editbanner').onclick=function(){editbanner(myvar);}; // }
<button onclick="javascript:settingvariables();">page highlight1</button> <button onclick="javascript:loadsynchpage(avar);">page highlight2</button> page name: <p id="pagename"></p> page name string: <p id="pagenamestring"></p> page length: <p id="pagelength"></p> character difference: <p id="characterdifference"></p> page name location: <p id="pagenamelocation"></p> character difference number:<p id="characterdifferencenumber"></p> node number start: <p id="nodenumberstart"></p> node number end: <p id="nodenumberend"></p> node number: <p id="nodenumber"></p>
2nd question: save script (not including <script>
tags) myjs.js, put same directory next page.html, , remove whole <script>
block html, , put instead of it:
<script src="myjs.js"></script>
Comments
Post a Comment