scope using html object tag - javascript

I have an HTML file, parent.html which has a link to a javascript file code.js with a whole lot of functionality in it.
The HTML file parent.html also loads another HTML page using the <object>tag.
This file is called child.html. It makes reference to the code which is in code.js. It calls a function when a button is clicked in the child.html file.
I keep getting an "Uncaught ReferenceError".
How can I fix this issue?
I thought that because my js file was added to the parent level file, that it would be accessible to the children files.

Related

panel has to be double-clicked if using external JS, but single click if script inside HTML body, don't understand

Here is the code - https://www.w3schools.com/howto/howto_js_accordion.asp.
I can setup just fine in a single HTML file, but I want to move the JS code to an external file.
I make the JS code in the external file a function and an "onclick" attribute, it has to be double-clicked as an external file, don't know how to fix this? Thanks.

Javascript FIle wont display simple code inside html file

Do I have to setup a javascript file like an html file so it can display the text i put in the
document.write("hello world!");
I have the <script> </script> inside the html but it still won't display the text i ask for
This is working for me.
<script>document.write("helloWorld")</script>
if you want to use javascript you have to put the actual js code into the script tag or link to an external script file.
It is recommended to set up the external file >like your html file< and to link to it inside of an <script> tag at the bottom of the html document. The filename could be App.js and you would have to link to it like this html <script src="./App.js"></script> (if the file is in the same folder). For more Information on this topic you could read this: seperation of concerns(Wikipeda)

My script src in HTML is not calling and activating my javascript file successfully

<!-- Custom JavaScript file -->
<scrpit src="./js/main.js"></scrpit>
If I press control+click on this src name, i go successfully to javascript file that i want to activate (which should mean that I have wrote the file's name and place well enough), but when i open the html page the functions in the script do not work.
To check if the problem is within the js code, i went and copied the js code inside the the html file, which worked properly.
But why wouldnt it work when i put it in a separate js file and call the file in the manner above?
I think there is a typo in your code.
Your code:
<scrpit src="./js/main.js"></scrpit>
Try to use this:
<script src="./js/main.js"></script>

JS overlay without direct access to html

I am attempting to add a javascript overlay onload, without direct access to the html. I'm only able to upload .js and .css files.
How would I go about doing this, I've searched all over, but as I am no expert at this I'm seeking a simple solution which will allow me to maybe call html and insert it into an overlay, by using javascript only.
I am unsure of the coding of the .js file to contain all of the overlay code and html code combined.
I've been looking at document.getElementById and document.write to do this, am I correct in trying to do it this way?
Any suggestions?
There is no way you can add an overlay to an existing html file without importing the new JS and CSS files in the html file. How ever, if there are other JS files used or imported to the HTML file, edit it and add your code in the JS file. It'll run since the JS file is already imported in the HTML.

Javascript function not getting called. Firebug shows reference error

I am writing a form and trying to call a javascript function
<form onSubmit="$('<%$containerName%>').update(''); submitForReinstate(this, $('<%$containerName%>')); return false;">
but when I run this, FireBug shows "ReferenceError: submitForReinstate is not defined". But this function is defined in some other file. Do I need to link both the files in some manner?
Can anyone please give me a pointer as to how to solve this?
I searched thoroughly on google but couldn't find the answer.
"But this function is defined in some other file. Do I need to link both the files in some manner?"
Yes. Assuming the first file contains html, which yours seems to given the <form> element you show, you include a reference to the second file within the first. The second file would need to contain just JavaScript (no <script> tags), and then in the main file add this:
<script src="nameofotherfile.js"></script>
If the file isn't in the same directory include an appropriate path in the src attribute.
The two most common places to add <script> elements are within the <head> section or just before the closing </body> tag.

Categories