PDA

View Full Version : How Can I Load De Content Of A Website Using JS. Please I Dont't Want To Use Frame.



Dealmightyera
11-10-2016, 05:55 AM
I am tryin to include another webpage content to my webpage by this code, but it not working.


<!Doctype html>
<html>
<head>
<script>
function include(destination) {
var e=window.document.createElement('script'); e.setAttribute('src',desti nation);
window.document.body.appendChild(e);
}</script>
</head>
<body onLoad="include('http://mywapsite.com');">
</body>
</html>

jscheuer1
11-10-2016, 04:06 PM
You can't exactly include "content" in this manner, you can include a script though. If the content at mywapsite is a script, it will work, but your syntax has an error and even if it were correct would do nothing more, perhaps even less than just using a script tag would do:


<script src="http://mywapsite.com">

And it would really depend upon what's in the script, as to whether or not it would show any content or do anything.

As for actually including one web site into another, browsers generally block that. Iframe is a possibility, but sometimes the remote site will block that and you say you don't want that. Content can be included using AJAX, but except in special cases, it must be from the same domain as the page it is being included on, then usually it's just data which then needs to be injected into the DOM of the receiving page. Server side languages like PHP and asp can be used to include content from a remote site, but the permissions on both the sites' hosts have to be set so as to allow it.

Dealmightyera
11-10-2016, 04:48 PM
Thanks, So How Can I Use Html/JS Load Document Of An External Webpage Using Iframe?.

styxlawyer
11-10-2016, 04:53 PM
It might help us understand your requirements a little better if you explain why you want to do this rather than just providing a link to the other page.

molendijk
11-10-2016, 09:30 PM
Also, you should tell us whether or not the 'other webpage' that you want to include in one or more of your pages belongs to the same domain as the page(s) where you want to insert it. If yes, it can easily be done with a few lines of javascript. If not, you can use an iframe.

Dealmightyera
11-10-2016, 10:58 PM
Thanks Guy's I've Figured it out by using html iframe.

Dealmightyera
11-22-2016, 11:34 AM
Please i'm trying 2 create a simple multiplication calculator using textarea and js function. this code is not working. i'm a noob in js.


<!DOCTYPE html>
<html>
<body>

<textarea id="t1"> </textarea> X <textarea id="t2"> </textarea> = <textarea id="ans"> </textarea>

<script>
var p1 = document.getElementById("t1").value;
var p2 = document.getElementById("t2").value;
function myFunction() {
return p1 * p2;
}
document.getElementById("ans").value;
</script>
<button type="button" onclick="myFunction()"> MULTIPLY </button>
</body>
</html>

styxlawyer
11-22-2016, 06:45 PM
Try this:



<!DOCTYPE html>
<html>
<body>

<textarea id="t1"> </textarea> X <textarea id="t2"> </textarea> = <textarea id="ans"> </textarea>

<script>
function myFunction() {
var p1 = document.getElementById("t1").value;
var p2 = document.getElementById("t2").value;
document.getElementById("ans").value = p1 * p2;
}
</script>
<button type="button" onclick="myFunction()"> MULTIPLY </button>
</body>
</html>