I have a little VBScript program embedded into a web page that displays hyperlinks but it overwites what was on the web page previous to running the script, how do I stop it overwrite what was previously on the page? script below
=?Utf-8?B?U3RldmU=?= wrote on 15 nov 2009 in microsoft.public.scripting.vbscript:
> I have a little VBScript program embedded into a web page that > displays hyperlinks but it overwites what was on the web page previous > to running the script, how do I stop it overwrite what was previously > on the page? script below
You cannot do a document.write when the page is loaded without doing an implicit document.open and so destroying the page as it was.
btw: 1 the () are not needed and should be discouraged in a VBS statement. 2 </a href> is nonsense html, try </a> 3 <br /> is xhtml, use <br> for html. 4 use quotes <a href='http://www.google.com'> 5 document.writeln only differs from document.write, that it gives a new line in the html source, having no effect on the rendered page.
==============
Whan you want to write something with clientside code into a page, you should write it into an element with innerHTML, or appensd it to an element with DOM manipulation.
Using vbs will only work in IE and not in any other browser, so it will be a very defunct webpage. Why not use JavaScript instead?
Thanks for your reply. I dont know anything about Javascript so I cant re-write the rest of the script. What web element should I write to? I tried writing to a text box but it just came out as text rather than a hyperlink
"Evertjan." wrote: > =?Utf-8?B?U3RldmU=?= wrote on 15 nov 2009 in > microsoft.public.scripting.vbscript:
> > I have a little VBScript program embedded into a web page that > > displays hyperlinks but it overwites what was on the web page previous > > to running the script, how do I stop it overwrite what was previously > > on the page? script below
> You cannot do a document.write when the page is loaded without doing an > implicit document.open and so destroying the page as it was.
> btw: > 1 the () are not needed and should be discouraged in a VBS statement. > 2 </a href> is nonsense html, try </a> > 3 <br /> is xhtml, use <br> for html. > 4 use quotes <a href='http://www.google.com'> > 5 document.writeln only differs from document.write, > that it gives a new line in the html source, > having no effect on the rendered page.
> ==============
> Whan you want to write something with clientside code into a page, you > should write it into an element with innerHTML, or appensd it to an > element with DOM manipulation.
> Using vbs will only work in IE and not in any other browser, so it will > be a very defunct webpage. Why not use JavaScript instead?
On Nov 15, 10:44 pm, Steve <St...@discussions.microsoft.com> wrote:
> I have a little VBScript program embedded into a web page that displays > hyperlinks but it overwites what was on the web page previous to running the > script, how do I stop it overwrite what was previously on the page? script > below
This script below shows two ways to append your links.
Set newLink = document.createElement("A") newLink.href = "http://google.com" newLink.innerText = "My link to Google" document.body.appendChild newLink
document.body.innerHTML = document.body.innerHTML & _ "<br><a href='http://ebay.com'>My link to eBay</a>"
The first way (first 4 lines) is the "more proper" way. The reason is because the second way can overwrite other things you may have done with your web page. For example, you will get an error if you append the following line to the code above:
MsgBox newLink.parentNode.outerHTML
since the act of rewriting the body, wipes out variables and event handlers and some other modifications that may have been set because the entire DOM is redone.
=?Utf-8?B?U3RldmU=?= wrote on 16 nov 2009 in microsoft.public.scripting.vbscript:
> Thanks for your reply. I dont know anything about Javascript so I cant > re-write the rest of the script. > What web element should I write to? I tried writing to a text box but it > just came out as text rather than a hyperlink
[Please do not toppost on usenet]
The vbs answer comes from Vienna.
However, either you do not mind to have a non-IE disfunctional webpage or you do.
If you do, better learn to use javascript.
-- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
In addition to the other ideas, you might want to look into insertAdjacentHTML. That method allows you to add new HTML in relation to any object. If you assign IDs to objects then it's easy to call. Also, createTextRange and the TextRange object provide ways to add or edit text.
I don't know whether these methods are the same in the DOM used by Firefox/Opera, but if you're only using VBS with IE you don't need to worry about that.
> I have a little VBScript program embedded into a web page that displays > hyperlinks but it overwites what was on the web page previous to running the > script, how do I stop it overwrite what was previously on the page? script > below
Great thanks for that. The script may need to display two or more hyperlinks down the page, how do I display the second and third ones? I tried the following line but it came up with an error?
"Csaba Gabor" wrote: > On Nov 15, 10:44 pm, Steve <St...@discussions.microsoft.com> wrote: > > I have a little VBScript program embedded into a web page that displays > > hyperlinks but it overwites what was on the web page previous to running the > > script, how do I stop it overwrite what was previously on the page? script > > below
> This script below shows two ways to append your links.
> Set newLink = document.createElement("A") > newLink.href = "http://google.com" > newLink.innerText = "My link to Google" > document.body.appendChild newLink
> document.body.innerHTML = document.body.innerHTML & _ > "<br><a href='http://ebay.com'>My link to eBay</a>"
> The first way (first 4 lines) is the "more proper" way. > The reason is because the second way can overwrite > other things you may have done with your web page. > For example, you will get an error if you append the > following line to the code above:
> MsgBox newLink.parentNode.outerHTML
> since the act of rewriting the body, wipes out variables > and event handlers and some other modifications that > may have been set because the entire DOM is redone.
"Csaba Gabor" wrote: > On Nov 15, 10:44 pm, Steve <St...@discussions.microsoft.com> wrote: > > I have a little VBScript program embedded into a web page that displays > > hyperlinks but it overwites what was on the web page previous to running the > > script, how do I stop it overwrite what was previously on the page? script > > below
> This script below shows two ways to append your links.
> Set newLink = document.createElement("A") > newLink.href = "http://google.com" > newLink.innerText = "My link to Google" > document.body.appendChild newLink
> document.body.innerHTML = document.body.innerHTML & _ > "<br><a href='http://ebay.com'>My link to eBay</a>"
> The first way (first 4 lines) is the "more proper" way. > The reason is because the second way can overwrite > other things you may have done with your web page. > For example, you will get an error if you append the > following line to the code above:
> MsgBox newLink.parentNode.outerHTML
> since the act of rewriting the body, wipes out variables > and event handlers and some other modifications that > may have been set because the entire DOM is redone.