Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Client-side Scripting _ variable in < OBJECT

Posted by: crlx2 Feb 4 2020, 06:34 PM

i need to show the text contained in a text file, so i used this html line:

<object id="file1" data="file1.txt"></object>

what i am not able to do is: how to use a variable instead of the string "file1.txt" ?

thanks


Posted by: Christian J Feb 4 2020, 08:26 PM

I think you could change the value of the DATA attribute with e.g.:

CODE
<button onclick="document.getElementById('file1').setAttribute('data','file2.txt');">...

but Firefox appears to be buggy.


Posted by: crlx2 Feb 5 2020, 04:14 AM

Dear Chistian J
i was not able to let it work (in chrome)
on setattribute i get an error: TypeError: Cannot read property 'setAttribute' of null


Posted by: Christian J Feb 5 2020, 07:44 AM

Could you post a sample of it?

Another solution might be to use server-side scripting (e.g. PHP) to read the text file, then browser support isn't an issue.

Posted by: crlx2 Feb 5 2020, 11:06 AM

Hi Christian
I understood that these things are too far from my competences and i gave up and found a work around with winsock,
thanks a lot for you kind help!


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)