This question already has answers here:
Share data between HTML pages
(4 answers)
Closed 2 years ago.
I have a project I'm working on that has multiple pages. Both of them have a JavaScript tag.
I want to be able to get a variable from the other one.
First HTML
<html>
<head></head>
<body>
<script>
var example = "stringText"
</script>
</body>
</html>
Second HTML
<html>
<head></head>
<body>
<script>
console.log(example)
</script>
</body>
</html>
I have tried making a .js file and saving a variable there and accessing it from the other file but it didn't work, the variable would clear itself when it got to the other page.
It is a possible way to approach.
Related
This question already has answers here:
execute a function after redirecting - javascript
(3 answers)
Closed 4 years ago.
<!DOCTYPE html>
<html>
<head>
<title>Experiment</title>
</head>
<body>
<script>
location.href = "https://www.bing.com";
function rere()
{
location.href = "https://www.google.com";
}
window.onload=function(){setTimeout(rere, 5000);};
</script>
</body>
</html>
I want to do following operations:
Go to a Location.
Wait until page loading.
Then go to a new location.
But, it stacked only at the first location.
Because the JavaScript is part of your currently open page. When a new page is loaded, it is stopped. So your Javascript is no longer running, now it's Bing's turn.
You might want to check iframes.
This question already has answers here:
Javascript Excel OpenFile
(2 answers)
Closed 5 years ago.
I want to open a excel document while loading a web page but i don't know how. I tried this:
<script>
function myFunction() {
window.open("file:///D://Files/doc.xlsx");
}
</script>
<body onload="myFunction()">
</body>
But it didn't work. I want to mention that it has to be done for IE8 and less.
Add tag <script> to <head>
<head>
<script>
function myFunction() {
window.open("file:///D://Files/doc.xlsx");
}
</script>
</head>
<body onload="myFunction()">
</body>
This question already has answers here:
Getting the current src of an Iframe using JQuery [duplicate]
(4 answers)
Closed 8 years ago.
Hello guys i kind of a javascript newbie.
Here is my problem
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<iframe name='frmExternal' id='frmExternal' src='www.dynamically-changing-url.com'></frame>
</body>
</html>
I want to get the current url in the iframe where the user browse along.
document.getElementsByName('frmExternal')[0].src
This question already has answers here:
JavaScript: Inline Script with SRC Attribute?
(3 answers)
Closed 8 years ago.
When I launch this in chrome, nothing appears on the page.
<!DOCTYPE html>
<head><title>test 4000</title><head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
document.writeln("test")
</script>
</body>
</html>
you are inserting code in a script tag that you are also using to load an external script (jQuery). you should either do the one or the other.
<script>
document.writeln("test");
</script>
if you want both do:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
document.writeln("test");
</script>
the reference states:
If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.
you do not need to include jQuery to use document.writeln()
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Creating a page that updates without reloading
I want to get the content of an HTML page from it's URL and put it somehwere in the current document. The pseudo-code below shows the approach I want to take:
<!DOCTYPE html>
<html>
<body>
<p id="text"></p>
<script type="text/javascript">
function getPageText(htmlPage)
{
//comment: How do I get innerHTML?
var text = htmlPage.body.innerHTML;
//comment: How do I have to return?
return text;
}
document.getElementById("text").innerHTML=getPageText("https://google.com");
</script>
</body>
</html>
The name of the technique you are looking for is AJAX --- You need to download the remote page (and it has to allow you to) in order for javascript to get the content of the page.
see another answer for an overview of that technique --- https://stackoverflow.com/a/10168402/473914
you need to extract content from google and then you could use innerHtml. Alternatively you can use iframe and wrap scr dynamically or statically. code for wraping scr dynamically is as follow.
a.html
<html>
<head>
<script>
function getPageText(url){
document.getElementById("container").setAttribute("src",url);
}
getPageText("https://www.google.com");
</script>
</head>
<body>
<iframe id='container'></iframe>
</body>
</html>