Ok, I searched lots of sites, but didn't find the answer. I'm wondering how to I make it so that it automatically brings you to a webpage, without a link having to been clicked?
Offline
You mean like, when you go to a page, it automatically forwards you somewhere else?
Read.
Offline
Is there a code in javascript for
if contents_from_file("file url") = "selected contents"
{
method
}
Offline
<?php
$fileContents = file_get_contents("URL to file");
?>
<script type = "text/javascript">
if(<?php echo $fileContents; ?> == "selected contents"){
code
}
</script>This is just off the top of my head. There may be a javascript equivalent to the php file_get_contents() method you can use rather than using a php variable.
Offline
put this in the <head> and </head> tags:
<script type="text/javascript">
window.location=('http://www.google.com')
</script>change http://www.google.com to the website you want to redirect to
Last edited by nathanprocks (2011-09-11 07:26:56)
Offline
nathanprocks wrote:
put this in the <head> and </head> tags:
Code:
<script type="text/javascript"> window.location=('http://www.google.com') </script>change http://www.google.com to the website you want to redirect to
Out of interest, does the js redirect allow variables in it? I've found that the php redirect function won't work if you try to put variables into the URL whilst thankfully the HTTP meta redirect function allows them
Offline
sparks wrote:
nathanprocks wrote:
put this in the <head> and </head> tags:
Code:
<script type="text/javascript"> window.location=('http://www.google.com') </script>change http://www.google.com to the website you want to redirect to
Out of interest, does the js redirect allow variables in it? I've found that the php redirect function won't work if you try to put variables into the URL whilst thankfully the HTTP meta redirect function allows them
![]()
like this?
<script type="text/javascript"> var google = "http://www.google.com" window.location=(google) </script>
Offline
sparks wrote:
more like
Code:
<script type="text/javascript"> var type = "Operators" window.location=('http://www.somesite.com/typesearch?type=' + type) </script>
yeah that would work!
search for 'variables' with google:
<script type="text/javascript">
var search = "variables"
window.location=('http://www.google.com/search?q=' + search)
</script>and i also just found out that u can put spaces in google without using + in the address bar
Last edited by nathanprocks (2011-09-11 07:48:19)
Offline
sparks wrote:
Oh yes, a lot of search engines and search filters use + to indicate seperate search terms and _ to indicate two words that are part of a single search term like shirley_bassey+singer
![]()
lol i put a space in the search variable between two words and it changed to %20 which also works
i always thought u had to put +
Offline
I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):
<script type="text/javascript">
<!--
window.location = "javascript:login()"
//-->
</script>
<script type="text/javascript">
function login()
{
var username=prompt("Please enter your username:");
var password=prompt("Please enter your password:");
}
</script>
<?php
$fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password);
?>
<script type = "text/javascript">
if(<?php echo $fileContents; ?> == "false"){
<?php echo "Invalid Details" ?>
}
else {
} </script>
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter a username:");
var projectid=prompt("Please enter a project ID:");
if (projectid!=null && projectid!="")
{
window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid;
}
}
</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Open a Project" />
</body>
</html>Offline
WindowsExplorer wrote:
I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):
Code:
<script type="text/javascript"> login() // Error here (I think). </script> <script type="text/javascript"> function login() { var username=prompt("Please enter your username:"); var password=prompt("Please enter your password:"); } </script> <?php $fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password); ?> <script type = "text/javascript"> if(<?php echo $fileContents; ?> == "false"){ <?php echo "Invalid Details" ?> } else { } </script> <html> <head> <script type="text/javascript"> function show_prompt() { var name=prompt("Please enter a username:"); var projectid=prompt("Please enter a project ID:"); if (projectid!=null && projectid!="") { window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid; } } </script> </head> <body> <input type="button" onclick="show_prompt()" value="Open a Project" /> </body> </html>
Offline
WindowsExplorer wrote:
I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):
Code:
<script type="text/javascript"> <!-- window.location = "javascript:login()" //--> </script> <script type="text/javascript"> function login() { var username=prompt("Please enter your username:"); var password=prompt("Please enter your password:"); } </script> <?php $fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password); ?> <script type = "text/javascript"> if(<?php echo $fileContents; ?> == "false"){ <?php echo "Invalid Details" ?> } else { } </script> <html> <head> <script type="text/javascript"> function show_prompt() { var name=prompt("Please enter a username:"); var projectid=prompt("Please enter a project ID:"); if (projectid!=null && projectid!="") { window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid; } } </script> </head> <body> <input type="button" onclick="show_prompt()" value="Open a Project" /> </body> </html>
It's quite obvious that you need
<body onload="login()">
instead of
<script type="text/javascript"> <!-- window.location = "javascript:login()" //--> </script>
Offline
sparks wrote:
Code:
<?php $fileContents = file_get_contents("URL to file"); ?> <script type = "text/javascript"> if(<?php echo $fileContents; ?> == "selected contents"){ code } </script>This is just off the top of my head. There may be a javascript equivalent to the php file_get_contents() method you can use rather than using a php variable.
It doesn't work.
Offline
Hmmm, well I haven't tested it but I can't see anything wrong with it. you could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.
Offline
sparks wrote:
Then I have no idea, I'm afraid.
Exact phrasing much? [
]
Last edited by LS97 (2011-09-11 09:59:03)
Offline
sparks wrote:
Then I have no idea, I'm afraid.
I need it for making a thing where you need to login with your Scratch account.
Offline
sparks wrote:
Then I have no idea, I'm afraid.
It doesn't work because you forgot to add javascript double quotes outside the PHP echo.
Offline
LS97 wrote:
sparks wrote:
Then I have no idea, I'm afraid.
It doesn't work because you forgot to add javascript double quotes outside the PHP echo.
sparks wrote:
Hmmm, well I haven't tested it but I can't see anything wrong with it. You could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.
WindowsExplorer wrote:
Still not working.
Offline
sparks wrote:
LS97 wrote:
sparks wrote:
Then I have no idea, I'm afraid.
It doesn't work because you forgot to add javascript double quotes outside the PHP echo.
sparks wrote:
Hmmm, well I haven't tested it but I can't see anything wrong with it. You could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.
WindowsExplorer wrote:
Still not working.
oh, oops.
Anyway, why don't you just use PHP since you can?
header('Location')?
Offline